Skip to content

Instantly share code, notes, and snippets.

@cjus
Last active July 12, 2023 14:59
Show Gist options
  • Save cjus/b46a243ba610661a7efb to your computer and use it in GitHub Desktop.
Save cjus/b46a243ba610661a7efb to your computer and use it in GitHub Desktop.
AngularJS Nginx and html5Mode
server {
server_name yoursite.com;
root /usr/share/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
@mscoobby
Copy link

@cjus Thank you!

@psk11
Copy link

psk11 commented Aug 12, 2017

What about two angular apps?
`

    listen       80;
    server_name  localhost;


    location /app1 {
        root /usr/share/nginx/app1;
        index index.html index.htm;
    }

    location /app2 {
        root /usr/share/nginx/app2;
        index index.html index.htm;
    }

`

What will be the nginx configs for two angular apps deployed on same server with html5mode? The above example is working fine for hashbang url's but not for the former one.

@SamuelMarks
Copy link

@psk11 This worked for me:

location /site0 {
    try_files $uri$args $uri$args/ /index.html;
    root   /var/www/static/site0/dist;
    index  index.html index.htm;
}

location /site1 {
    try_files $uri$args $uri$args/ /index.html;
    root   /var/www/static/site1/dist;
    index  index.html index.htm;
}

@sumitramteke
Copy link

Thanks @jpduckwo, your solution works for me. I guess in gist there's no way to thumbs up.

@cescgie
Copy link

cescgie commented Nov 28, 2017

@cjus this saves my time

@clov0
Copy link

clov0 commented Jan 17, 2018

Really Helped
Thanks

@mattisebastian
Copy link

You guys saved me a lot of time, thank you!

@royge
Copy link

royge commented Oct 25, 2018

Thanks @jpduckwo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment