Report this

What is the reason for this report?

Nginx multiple locations + static files

Posted on April 27, 2015
kapa

By kapa

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.