Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
895 views
in Technique[技术] by (71.8m points)

docker - How to serve angular with nginx with a relative path

I'm bit lost on how serve my angular app with nginx. The requirements are that the url for accessing the app will fall under: www.domain-name.com/rte

I have the app files on a docker on the path: /usr/share/nginx/html/

And my default.conf looks like:

  location /rte {
    alias /usr/share/nginx/html/;
    try_files $uri$args $uri$args $uri $uri/ /index.html;
  }

But when I try to access the page, a timeout happens.

I've tried with this aswel:

  location /rte/ 

and a 404 is thrown.

Edit: my index.html has -> base href="/"

question from:https://stackoverflow.com/questions/65902398/how-to-serve-angular-with-nginx-with-a-relative-path

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution was to add /rte/ on try_files $uri$args $uri$args $uri $uri/ /rte/index.html;

And as Richards commented, I had to add the /rte/ on the index html base href as well:

base href="/rte/"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...