-
-
Save henrytran9x/f6bbb7eac79e82fdf1d2663a932b721e to your computer and use it in GitHub Desktop.
Nginx virtual host configuration for WordPress
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 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 /path/to/www; | |
index index.php; | |
charset UTF-8; | |
gzip on; | |
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; | |
gzip_http_version 1.1; | |
gzip_vary on; | |
gzip_comp_level 6; | |
gzip_proxied any; | |
# Browser cache | |
location ~ \.(css|htc|js|js2|js3|js4)$ { | |
expires 31536000s; | |
add_header Pragma "public"; | |
add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; | |
} | |
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ { | |
expires 3600s; | |
add_header Pragma "public"; | |
add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate"; | |
} | |
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ { | |
expires 31536000s; | |
add_header Pragma "public"; | |
add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; | |
} | |
# Server logs | |
access_log /path/to/logs/access.log; | |
error_log /path/to/logs/error.log debug; | |
# favicon | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
# robots.txt | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
# Deny access to version control repository metadata | |
location ~ /\.(git|svn)/* { | |
deny all; | |
} | |
# Deny access to hidden files | |
location ~ \.(ht|gitignore$) { | |
deny all; | |
} | |
# Deny access to WordPress include-only files | |
location ~ ^/wp-admin/includes/ { | |
deny all; | |
} | |
location ~ ^/wp-includes/[^/]+\.php$ { | |
deny all; | |
} | |
location ~ ^/wp-includes/js/tinymce/langs/.+\.php { | |
deny all; | |
} | |
location ~ ^/wp-includes/theme-compat/ { | |
deny all; | |
} | |
location /nginx_status { | |
stub_status on; | |
access_log off; | |
} | |
location ~ ^/nginx\/(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 / { | |
try_files $uri $uri/ /index.php?q=$uri&$args; | |
} | |
location ~ \.php$ { | |
set $nocache ""; | |
if ($http_cookie ~ (comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) { | |
set $nocache "Y"; | |
} | |
try_files $uri =404; | |
# HHVM | |
# fastcgi_pass 127.0.0.1:9000; | |
# PHP-FPM | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /path/to/www$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_valid 200 1m; | |
fastcgi_cache_bypass $nocache; | |
fastcgi_no_cache $nocache; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment