I have a web app that has static content and can serve dynamic pages and secure content.
Static content lies in /public
folder and should be served directly by nginx
.
Dynamic content is served by 127.0.0.1:3000
upstream.
Secure content is also served by the upstream and available from /assets/*
URLs. This secure content may have the same file extensions as static content, but it always lies in /assets/
.
I have a working nginx
configuration with two locations with the same proxying rules.
Is there any way to reduce my config somehow joining the two locations served by the upstream?
server {
server_name example.name;
root /home/user/ruby18/app/public;
try_files $uri @thin;
location ^~ /assets/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://thin;
}
location ~* \.(jpeg|jpg|gif|png|ico|css|bmp|js)$ {
root /home/user/ruby18/app/public;
}
location @thin {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://thin;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
upstream thin {
server 127.0.0.1:3000;
}