Last active
December 18, 2015 04:08
-
-
Save pacojp/5722706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream backend { | |
server unix:/var/run/nginx-backend.sock; | |
} | |
# inner reverse proxy(for cache) | |
server { | |
listen 3000; | |
#server_name www.example.com; | |
server_name _; | |
root /var/www/example.com/public_html; | |
index index.html index.htm index.php; | |
access_log /var/log/nginx/example.com/access.log; | |
error_log /var/log/nginx/example.com/error.log; | |
#try_files $uri $uri/ /index.php?q=$uri&$args; | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
rewrite ^(.*)(index|home|default)\.html? $1 permanent; | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
location = /apple-touch-icon.png { access_log off; log_not_found off; } | |
location = /apple-touch-icon-precomposed.png { access_log off; log_not_found off; } | |
location ~ /\. { deny all; access_log off; log_not_found off; } | |
set $mobile ''; | |
if ($http_user_agent ~* '(DoCoMo|J-PHONE|Vodafone|MOT-|UP\.Browser|DDIPOCKET|ASTEL|PDXGW|Palmscape|Xiino|sharp pda browser|Windows CE|L-mode|WILLCOM|SoftBank|Semulator|Vemulator|J-EMULATOR|emobile|mixi-mobile-converter)') { | |
set $mobile '@ktai'; | |
} | |
if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') { | |
set $mobile '@smartphone'; | |
} | |
if ($http_cookie ~* "wptouch(_switch_cookie=normal|-pro-view=desktop)") { | |
set $mobile "@smartphone.desktop"; | |
} | |
location ~* /wp-(content|admin|includes) { | |
index index.php index.html index.htm; | |
if ($request_filename ~* .*\.(xml|gz)) { | |
break; | |
expires 1d; | |
} | |
if ($request_filename ~* .*\.(txt|html?|js|css|swf)) { | |
break; | |
expires 30d; | |
} | |
if ($request_filename ~* .*\.(ico|jpe?g|gif|png|wmv|flv|mpg|gz)) { | |
break; | |
expires 365d; | |
} | |
if ($request_filename ~ .*\.php) { | |
break; | |
proxy_pass http://backend; | |
} | |
} | |
location /feed { proxy_pass http://backend; } | |
location ~ .*\.php { proxy_pass http://backend; } | |
location / { | |
set $do_not_cache 0; | |
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) { | |
set $do_not_cache 1; | |
} | |
if ($request_method = POST) { | |
set $do_not_cache 1; | |
} | |
proxy_no_cache $do_not_cache; | |
proxy_cache_bypass $do_not_cache; | |
proxy_redirect off; | |
proxy_cache one; | |
proxy_cache_key "$scheme://$host$request_uri$mobile"; | |
proxy_cache_valid 200 5m; | |
proxy_cache_valid 404 5m; | |
proxy_pass http://backend; | |
} | |
} | |
# backend server | |
server { | |
listen unix:/var/run/nginx-backend.sock; | |
server_name _; | |
root /var/www/example.com/public_html; | |
access_log /var/log/nginx/backend.access.log backend; | |
gzip off; | |
gzip_vary off; | |
location / { | |
index index.php index.html index.htm; | |
try_files $uri $uri/ /index.php?$args /index.php?q=$uri&$args; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
expires off; | |
# phpfpm defined at nginx.conf | |
fastcgi_pass phpfpm; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
fastcgi_param REMOTE_ADDR $http_x_real_ip; | |
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"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment