kapa
By:
kapa

Nginx multiple locations + static files

April 27, 2015 5.9k views
Nginx

Hello,

I am trying to create the following setup with nginx:

subdomain.test.com
subdomain.test.com/admin

I want nginx to serve static files (js, css, images etc) and everything else by the application I have running on the give ports.

For test.com it works as expected, but for test.com/admin the javascript and css files (found under /dist) are loaded from /var/www/test/main (test.com's root)

My confing looks like:

server {

        listen 80;

        index index.html index.htm;

        server_name subdomain.test.com;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        location ~ ^/(app/|images/|img/|javascript/|js/|css/|dist/|media/|static/|robots.txt|humans.txt|favicon.ico) {
            root /var/www/test/main;
            access_log off;
            expires max;
        }

        location ~ / {
            proxy_pass http://localhost:232;
        }

        location ~ ^/admin/(app/|images/|img/|javascript/|js/|css/|dist/|media/|static/|robots.txt|humans.txt|favicon.ico) {
            root /var/www/test/admin;
            access_log off;
            expires max;
        }

        location ~ /admin {
            proxy_pass http://localhost:233;
            rewrite ^/admin.* /$1 break;
        }
}

Regards,
kapa

1 Answer

Hi, kapa.

Did you find the solution for this problem?

Have another answer? Share your knowledge.