Ubuntu/webserver/nginx/proxy

From MattWiki
< Ubuntu‎ | webserver‎ | nginx
Jump to: navigation, search
noteThis Page was written with Ubuntu 12.04 LTS in mind, and may not work correctly with other versions or distributions.

Gallery3 Reverse Proxy

# Proxied sites back to offsite.example.com
proxy_ignore_headers   Expires Cache-Control;
proxy_cache_use_stale  error timeout invalid_header http_502;
proxy_cache_valid      200 302 90d;
proxy_cache_path       /var/cache/nginx/gallery levels=1:2 keys_zone=gallery:100m max_size=1024m inactive=90d;
proxy_temp_path        /var/cache/nginx/temp;

# Upstream to abstract backend connection(s) for PHP.
upstream php {
   server unix:/var/run/php5-fpm.socket;
}

#gallery.example.com
upstream gallery.example.com {
    server 111.222.111.222:9000;
}
     
server {
    listen 80;
    listen [::]:80;
    server_name gallery.example.com;
    
    proxy_http_version 1.1;
    proxy_connect_timeout 75s;
    proxy_cache_use_stale error timeout updating;
    proxy_cache_valid 2630000m;
    
    location /var/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/var/;
    }
    
    location /lib/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/lib/;
    }
    
    location /themes/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/themes/;
    }
    
    location /modules/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/modules/;
    }
    
    location /combined/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/combined/;
        proxy_ignore_headers        X-Accel-Expires Expires Cache-Control Set-Cookie;
    }
    
    location /items/dimensions/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/items/dimensions/;
    }
    
    location /exif/show/ {
        expires 180d;
        proxy_cache       gallery;
        proxy_pass        http://gallery.example.com/exif/show/;
    }
    
    location / {
        limit_req         zone=one  burst=5;
        proxy_pass        http://gallery.example.com;
    }
}

MediaWiki Reverse Proxy

# Proxied sites back to offsite.example.com
proxy_ignore_headers   Expires Cache-Control;
proxy_cache_use_stale  error timeout invalid_header http_502;
proxy_cache_valid      200 302 90d;
proxy_cache_path       /var/cache/nginx/mediawiki levels=1:2 keys_zone=mediawiki:100m max_size=512m inactive=90d;
proxy_temp_path        /var/cache/nginx/temp;

# Upstream to abstract backend connection(s) for PHP.
upstream php {
   server unix:/var/run/php5-fpm.socket;
}

# mediawiki.example.com
upstream mediawiki.example.com {
    server 111.222.111.222:9000;
}

server {
    listen 80;
    listen [::]:80;
    server_name mediawiki.example.com;
    
    proxy_set_header      X-Real-IP  $remote_addr;
    proxy_set_header      Host $host;
    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    
    location /images/ {
        proxy_pass        http://mediawiki.example.com/images/;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_cache_valid 200 120m;
        proxy_cache       mediawiki;
        proxy_cache_use_stale error;
    }
    
    location /skins/ {
        proxy_pass        http://mediawiki.example.com/skins/;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_cache_valid 200 120m;
        proxy_cache       mediawiki;
        proxy_cache_use_stale error;
    }

    location / {
        proxy_pass         http://mediawiki.example.com;
        proxy_set_header   X-Real-IP  $remote_addr;
    }
}