Skip to content

Instantly share code, notes, and snippets.

@iansheridan
Last active December 19, 2015 00:59
Show Gist options
  • Save iansheridan/5872311 to your computer and use it in GitHub Desktop.
Save iansheridan/5872311 to your computer and use it in GitHub Desktop.
sample Nginx config for proxying
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment