Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
nginx reverse proxy config
proxy_cache_path /var/lib/nginx/cache/staticfiles levels=1:2 keys_zone=staticfilecache:120m inactive=180m max_size=50m;
proxy_cache_path /var/lib/nginx/cache/php levels=2:2 keys_zone=php:10m inactive=180m max_size=50m;
proxy_temp_path /var/lib/nginx/proxy;
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_send_timeout 120;
#IMPORTANT - this sets the basic cache key that's used in the static file cache.
proxy_cache_key "$scheme://$host$request_uri";
upstream apache {
# server;
server {
#Only cache 200 responses, and for a default of 20 minutes.
proxy_cache_valid 200 20m;
#Listen to your public IP
listen 80 default_server;
server_name _;
#Probably not needed, as the proxy will pass back the host in "proxy_set_header"
#access_log /var/log/nginx/yoursite.proxied.log;
# "combined" matches apache's concept of "combined". Neat.
access_log /var/log/nginx/combined-access.log combined;
access_log /var/log/nginx/gzip-access.log gzip;
# Set the real IP.
proxy_set_header X-Real-IP $remote_addr;
# Set the hostname
proxy_set_header Host $host;
#Set the forwarded-for header.
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-NginX-Proxy true;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain application/xml text/javascript;
gzip_disable "MSIE [1-6]\.";
location / {
proxy_pass http://apache/;
proxy_redirect http://apache/ http://$host/;
location /evan/ {
proxy_pass http://apache/evan/;
proxy_redirect http://apache/ http://$host/;
proxy_cache php;
proxy_cache_valid 200 30m;
expires 5m;
location /evan/wp-admin/ {
proxy_pass http://apache/evan/wp-admin/;
proxy_redirect http://apache/ http://$host/;
location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|ico)$ {
# Cache static-looking files for 120 minutes, setting a 10 day expiry time in the HTTP header,
# whether logged in or not (may be too heavy-handed).
proxy_cache_valid 200 120m;
expires 864000;
proxy_pass http://apache;
proxy_cache staticfilecache;
location = /50x.html {
root /var/www/nginx-default;
# No access to .htaccess files.
location ~ /\.ht {
deny all;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment