Skip to content

Instantly share code, notes, and snippets.

@ftkro
Created November 14, 2014 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftkro/0261af24d511f333758a to your computer and use it in GitHub Desktop.
Save ftkro/0261af24d511f333758a to your computer and use it in GitHub Desktop.
Nginx Backend
server {
listen unix:/var/run/nginx-backend.sock default;
server_name _;
root /path/to/your/root/directory;
index index.php index.html;
access_log /var/log/nginx/domain.backend.access.log backend;
keepalive_timeout 25;
port_in_redirect off;
gzip off;
gzip_vary off;
set $no_cache 0;
if ($request_method = POST) {
set $no_cache 1;
}
if ($query_string != "") {
set $no_cache 1;
}
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $no_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $no_cache 1;
}
set $mobile_request 0;
if ($http_user_agent ~* "(2\.0 MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine\/3\.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA\/WX310K|LG\/U990|MIDP-2\.|MMEF20|MOT-V|NetFront|Newt|Nintendo Wii|Nitro|Nokia|Opera Mini|Palm|PlayStation Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian OS|SymbianOS|TS21i-10|UP\.Browser|UP\.Link|webOS|Windows CE|WinWAP|YahooSeeker\/M1A1-R2D2|NF-Browser|iPhone|iPad|iPod|Android|BlackBerry9530|G-TU915 Obigo|LGE VX|webOS|Nokia5800)" ) {
set $mobile_request 1;
}
if ($http_cookie ~ 'wptouch-pro-view=desktop') {
set $mobile_request 0;
}
location / {
include /etc/nginx/template/expires;
try_files $uri $uri/ /index.php?$args;
open_file_cache max=100;
}
rewrite /wp-admin$ $uri/ permanent;
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
include /etc/nginx/template/expires;
log_not_found off;
}
location ~* /wp-(config|blog-header|load)\.php$ { access_log /dev/null; log_not_found off; return 404; }
location ~* (readme|readme-[^\.]+)\.(txt|html?)$ { access_log /dev/null; log_not_found off; return 404; }
if (-f $request_filename) {
break;
}
location ~ \.php$ {
limit_req zone=method;
try_files $uri =404;
expires off;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass phpfpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_param REMOTE_ADDR $http_x_real_ip;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header "X-Accel-Redirect";
fastcgi_pass_header "X-Accel-Buffering";
fastcgi_pass_header "X-Accel-Charset";
fastcgi_pass_header "X-Accel-Expires";
fastcgi_pass_header "X-Accel-Limit-Rate";
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache fastcgizone;
fastcgi_cache_valid 60m;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment