Serve multiple Angular apps from the same server with Nginx

前端 未结 6 1049
臣服心动
臣服心动 2020-12-30 02:59

I\'m serving multiple angular apps from the same server block in Nginx. So in order to let the user browse directly to certain custom

6条回答
  •  我在风中等你
    2020-12-30 03:23

    Hope this helps someone

    Step 1 - Build all your projects

    ng build --prod --base-href /project1/
    ng build --prod --base-href /project2/
    ng build --prod --base-href /project3/
    

    Step 2 - Configure your nginx, note the change added in try_files section

    server {
        listen 80;
        server_name website.com;
    
        # project1
        location / {
            alias /home/hakim/project1/dist/;
            try_files $uri/ /project1/index.html;
        }
    
        # project2
        location /project2/ {
            alias /home/hakim/project2/dist/;
            try_files $uri/ /project2/index.html;
        }
    
        # project3
        location /project3/ {
            alias /home/hakim/project3/dist/;
            try_files $uri/ /project3/index.html;
        }
    }
    

    Step 3 - Reload nginx configuration

    sudo service nginx reload
    

提交回复
热议问题