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
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
You could try my nginx configuration file Config model1:
Explanation: the nginx server access file on localhost at /var/www/html/ its using
alias
so when http://yourhost.net/assets/x.js will looking into /var/www/html/assets/x.js and when there’s no file match with the user request it’ll pass to@fwdbackend
(which pass the user request to 10.10.0.3:81 [nodejs server])Config model2"
Hi, kapa.
Did you find the solution for this problem?