Welcome! Log In Create A New Profile

Advanced

Proxying and static files

February 16, 2017 08:26AM
Hi

I have a number of apps running behind nginx and I want to configure nginx so that is serves static content (js and css files) from the pulic directory of each app directly rather than proxying these requests, for example:

myserver.com/app1 dynamic requests proxied to hypnotoad (perl server) listening on http://*:5000, css/js files served directly by Nginx (example path app1/public/js/script.js)
myserver.com/app2 dynamic requests proxied to hypnotoad (perl server) listening on http://*:5001, css/js files served directly by Nginx (example path app2/public/js/script.js)
myserver.com/appN dynamic requests proxied to hypnotoad (perl server) listening on http://*:5..N, css/js files served directly by Nginx (example path app3/public/js/script.js)

My conf file:

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

# Root for stuff like default index.html
root /var/www/html;

location /app1 {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host:$server_port;
}

location /app2 {
proxy_pass http://127.0.0.1:5001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host:$server_port;
}

location /appN {...}
}

I've tried something like the following but can't get it work for each app:
location ~* /(images|css|js|files)/ {
root /home/username/app1/public/;
}

If I request app1/js/script.js for example it goes to /home/username/app1/public/app1/js/script.js rather than /home/username/app1/public/js/script.js

How can I get this to work for each app?
Subject Author Posted

Proxying and static files

epoch1 February 16, 2017 08:26AM

Re: Proxying and static files

Francis Daly February 16, 2017 04:40PM

Re: Proxying and static files

Alan Orth February 21, 2017 10:02AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 85
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready