Two Nginx configs that I use for external and internal proxies.
Here is a link to one of the companion configs that I also use on ruby systems.
Two Nginx configs that I use for external and internal proxies.
Here is a link to one of the companion configs that I also use on ruby systems.
upstream example_app { | |
server unix:/path/to/socket/example.sock fail_timeout=0; | |
} | |
server { | |
listen 80; | |
server_name www.example.com; | |
root /var/www; | |
index index.html index.htm index.php; | |
rewrite app_name$ /app_name/ permanent; | |
location /app_name/ { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
# static files for app specific files (not always needed eg. api's) | |
root /var/www/app_name/public; | |
# If you don't find the filename in the static files | |
# Then request it from the api server | |
if (!-f $request_filename) { | |
proxy_pass http://example_app; | |
break; | |
} | |
} | |
} |
upstream api_server { | |
server api.example.com fail_timeout=0; | |
} | |
server { | |
listen 80; | |
server_name www.example.com; | |
root /var/www; | |
index index.html index.htm index.php; | |
rewrite api$ /api/ permanent; | |
location /api/ { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
root /var/www; | |
# If you don't find the filename in the static files | |
# Then request it from the api server | |
if (!-f $request_filename) { | |
proxy_pass http://api_server; | |
break; | |
} | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} |