2

I'm serving 2 Angular apps inside same server block, production and demo.

I created the folders /var/www/myapp/demo e /var/www/myapp/prod

So when I type localhost/ should be serve prod and locahost/demo serve demo

I try the following config

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    index index.html;

    server_name _;

    root /var/www/myapp;

    location / {
        root /var/www/myapp/prod;
    }

    location /demo {        
        root /var/www/myapp/demo;
    }

} 

And no success.

I trid others variations, but nothing until here

How can i configure my server block to make this work.

Thanks

2
  • Remove both location blocks. – Michael Hampton Mar 13 '17 at 23:28
  • That way http://localhost/ won't serve the /var/www/myapp/prod directory. – Tero Kilkanen Mar 14 '17 at 2:03
2

In nginx, the path specified in location is added after the directory specified in root.

So, in this case nginx tries to load your demo version from /var/www/myapp/demo/demo.

This configuration should work provided that your configuration for the application server is correct in nginx.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    index index.html;

    server_name _;

    location / {
        root /var/www/myapp/prod;
    }

    location /demo {
        root /var/www/myapp;
    }
}
2
  • That works and I undestood, thank you! Just one more question. And if serve /demo in another directory, like /dev? – Vinicius Cunha Mar 14 '17 at 13:17
  • Then you need to use alias /var/www/myapp/dev; – Tero Kilkanen Mar 14 '17 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.