-
-
Save samayo/1910bb2a51a04056bc9532bbae5f9301 to your computer and use it in GitHub Desktop.
Wordpress Nginx Config
This file contains 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
# --------------------------------------- | |
# Main Module | |
# --------------------------------------- | |
user nginx; | |
# This number should be, at maximum, the number of CPU cores on your system. | |
worker_processes 2; | |
pid /var/run/nginx.pid; | |
# Only log critical errors | |
error_log /var/log/nginx/error.log crit; | |
# --------------------------------------- | |
# Events Module | |
# --------------------------------------- | |
events { | |
worker_connections 8192; | |
multi_accept on; | |
# Essential for linux optmized to serve many clients with each thread | |
use epoll; | |
} | |
# --------------------------------------- | |
# HTTP Core Module | |
# --------------------------------------- | |
http { | |
# | |
# Basic Settings | |
# | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
# | |
# Logging | |
# | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
# Buffer log writes to speed up IO, or disable them altogether | |
# access_log /var/log/nginx/access.log main buffer=16k; | |
access_log off; | |
# | |
# Buffer + Timeouts | |
# | |
# Sendfile copies data between one FD and other from within the kernel. | |
# More efficient than read() + write(), since the requires transferring data to and | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
types_hash_max_size 2048; | |
# Close connections to the client if the client does not respond within a fixed period by various timeout directives. | |
keepalive_timeout 30; | |
keepalive_requests 10000; | |
reset_timedout_connection on; | |
client_body_timeout 10; | |
send_timeout 2; | |
# | |
# File Cache Settings | |
# | |
# Cache | |
open_file_cache max=200000 inactive=20s; | |
open_file_cache_valid 30s; | |
open_file_cache_min_uses 2; | |
open_file_cache_errors on; | |
# Gzip Compression | |
gzip on; | |
gzip_types text/css text/javascript application/x-javascript application/json text/xml; | |
gzip_min_length 500; | |
gzip_comp_level 5; | |
fastcgi_buffer_size 32k; | |
fastcgi_buffers 256 4k; | |
# Document root | |
root /user/share/nginx/www; | |
# | |
# Virtual Host Configs | |
# | |
include /etc/nginx/conf.d/*.conf; | |
include /etc/nginx/sites-enabled/*; | |
} |
This file contains 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
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_param SCRIPT_NAME $fastcgi_script_name; | |
fastcgi_param REQUEST_URI $request_uri; | |
fastcgi_param DOCUMENT_URI $document_uri; | |
fastcgi_param DOCUMENT_ROOT $document_root; | |
fastcgi_param SERVER_PROTOCOL $server_protocol; | |
fastcgi_param HTTPS $https if_not_empty; | |
fastcgi_param GATEWAY_INTERFACE CGI/1.1; | |
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; | |
fastcgi_param REMOTE_ADDR $remote_addr; | |
fastcgi_param REMOTE_PORT $remote_port; | |
fastcgi_param SERVER_ADDR $server_addr; | |
fastcgi_param SERVER_PORT $server_port; | |
fastcgi_param SERVER_NAME $server_name; | |
# PHP only, required if PHP was built with --enable-force-cgi-redirect | |
fastcgi_param REDIRECT_STATUS 200; |
This file contains 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
location / { | |
try_files $uri $uri/ /index.php?q=$uri&$args; | |
} | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location ~ /\.svn/* { | |
deny all; | |
} | |
location ~ /\.git/* { | |
deny all; | |
} | |
location /nginx_status { | |
stub_status on; | |
access_log off; | |
} | |
location ~ /\. { | |
deny all; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico|swf)$ { | |
expires max; | |
log_not_found off; | |
} | |
location = /wp-admin { | |
rewrite ^ /wp-admin/ permanent; | |
} | |
location ~ \.php(?:/|$) { | |
if (!-f $document_root$fastcgi_script_name){ | |
rewrite ^ /index.php break; | |
} | |
location ~ ^/(status|ping)$ { | |
include /etc/nginx/fastcgi_params; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; | |
allow 127.0.0.1; | |
deny all; | |
} | |
location ~ \.php$ { | |
set $nocache ""; | |
if ($http_cookie ~ (comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) { | |
set $nocache "Y"; | |
} | |
fastcgi_pass php-fpm; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_intercept_errors on; | |
include fastcgi_params; | |
fastcgi_cache_use_stale error timeout invalid_header http_500; | |
fastcgi_cache_key $host$request_uri; | |
fastcgi_cache example; | |
fastcgi_cache_valid 200 1m; | |
fastcgi_cache_bypass $nocache; | |
fastcgi_no_cache $nocache; | |
} |
This file contains 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 php-fpm { | |
server unix:/var/run/php5-fpm.sock; | |
} | |
server { | |
listen 80; | |
server_name www.example.com; | |
rewrite ^ http://example.com$request_uri?; | |
} | |
server { | |
listen 80; | |
server_name example.com; | |
root /var/www/example.com; | |
index index.php; | |
charset UTF-8; | |
# Buffer log writes to speed up IO, or disable them altogether | |
#access_log /var/log/nginx/example.com.access.log main buffer=16k; | |
#error_log /var/log/nginx/example.com.error.log; | |
access_log off; | |
include location_optmz.conf; | |
#include wp_super_cache.conf; | |
} |
This file contains 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
server { | |
listen 80 default; | |
server_name www.domain.com domain.com; | |
index index.php; | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ /\. { | |
deny all; | |
} | |
location ~ \.(css|js|jp(e)?g|gif|png|swf|ico)$ { | |
expires 1y; | |
} | |
location = /wp-admin { | |
rewrite ^ /wp-admin/ permanent; | |
} | |
include wp_super_cache; | |
location ~ \.php(?:/|$) { | |
if (!-f $document_root$fastcgi_script_name){ | |
rewrite ^ /index.php break; | |
} | |
fastcgi_split_path_info ^(.+\.php)(.*)$; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
allow 127.0.0.1; | |
deny all; | |
} | |
} |
This file contains 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
set $supercacheuri ""; | |
set $supercachefile "$document_root/wp-content/cache/supercache/${http_host}${uri}index.html.gz"; | |
if (-e $supercachefile) { | |
set $supercacheuri "/wp-content/cache/supercache/${http_host}${uri}index.html.gz"; | |
} | |
# If this is a POST request, pass the request onto WordPress. | |
if ($request_method = POST) { | |
set $supercacheuri ""; | |
} | |
# If there is a query string, serve the uncached version. | |
if ($query_string) { | |
set $supercacheuri ""; | |
} | |
# Logged in users and those who have posted a comment get the non-cached version. | |
if ($http_cookie ~* comment_author_|wordpress_logged_in|wp-postpass_) { | |
set $supercacheuri ""; | |
} | |
# Mobile browsers get the non-cached version. | |
# Wastes CPU cycles if there isn't a mobile browser WP theme for the site. | |
if ($http_x_wap_profile) { | |
set $supercacheuri ""; | |
} | |
if ($http_profile) { | |
set $supercacheuri ""; | |
} | |
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|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) { | |
set $supercacheuri ""; | |
} | |
if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) { | |
set $supercacheuri ""; | |
} | |
# Stop processing if the supercache file is valid. | |
if ($supercacheuri) { | |
rewrite ^ $supercacheuri break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment