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
393 views
in Technique[技术] by (71.8m points)

angular - 使用Nginx从同一服务器上服务多个Angular应用程序的资产(Serve assets of multiple Angular apps from the same server with Nginx)

I'm serving multiple angular apps from the same server block in Nginx.

(我正在Nginx的同一服务器块中提供多个角度应用程序。)

I'm forwarding these routes from nginx to each angular app's index.html, I've added a try_files to each location:

(我将这些路由从nginx转发到每个角度应用程序的index.html,并在每个位置添加了try_files:)

    listen 80;
    server_name website.com;

    # project1
    location / {
        root /home/www/html/project1/dist/;
        try_files $uri $uri/ /index.html;
    }

    # project2
    location /project2/ {
        root /home/www/html/project2/dist/;
        try_files $uri $uri/ /index.html;
    }
}

This solution avoids the 404 error when going to an Angular route, but the problem is that how could I route to assetes of each project

(此解决方案避免了在执行Angular路线时出现404错误的问题,但是问题是我该如何路由到每个项目的资产)

location /assets{
      ??
    }

Is there any config in nginx so without making changes in angular code , or change places of each project assets ?

(nginx中是否有任何配置,因此无需更改角度代码或更改每个项目资产的位置?)

  ask by asmaa mahmoud translate from so

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

1 Reply

0 votes
by (71.8m points)
等待大神答复

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

...