Skip to content

Instantly share code, notes, and snippets.

@henrytran9x
Forked from goblindegook/wordpress.nginxconf
Created February 21, 2019 08:07

Revisions

  1. @goblindegook goblindegook revised this gist Feb 19, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    server {
    listen 80;
    server_name www.example.com;
    rewrite ^ http://example.com$request_uri?;
    rewrite ^ $scheme://example.com$request_uri?;
    }

    server {
  2. @goblindegook goblindegook revised this gist Feb 19, 2014. 1 changed file with 12 additions and 7 deletions.
    19 changes: 12 additions & 7 deletions wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -36,22 +36,27 @@ server {
    # FastCGI cache exceptions
    ##

    set $cache_uri $request_uri;
    set $no_cache 0;
    set $cache_uri $request_uri;

    if ($request_method = POST) {
    set $cache_uri "null cache";
    set $cache_uri "null cache";
    set $no_cache 1;
    }

    if ($query_string != "") {
    set $cache_uri "null cache";
    set $cache_uri "null cache";
    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 $cache_uri "null cache";
    set $cache_uri "null cache";
    set $no_cache 1;
    }

    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
    set $cache_uri "null cache";
    set $cache_uri "null cache";
    set $no_cache 1;
    }

    ##
    @@ -154,8 +159,8 @@ server {
    # fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:10m max_size=1000m inactive=60m;
    # fastcgi_cache_key $scheme$host$request_uri$request_method;
    # fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    fastcgi_no_cache $nocache;
    fastcgi_cache_bypass $nocache;
    fastcgi_no_cache $no_cache;
    fastcgi_cache_bypass $no_cache;
    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid any 30m;
    }
  3. @goblindegook goblindegook revised this gist Feb 19, 2014. 1 changed file with 23 additions and 30 deletions.
    53 changes: 23 additions & 30 deletions wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -36,22 +36,22 @@ server {
    # FastCGI cache exceptions
    ##

    set $nocache 0;
    set $cache_uri $request_uri;

    if ($request_method = POST) {
    set $nocache 1;
    set $cache_uri "null cache";
    }

    if ($query_string != "") {
    set $nocache 1;
    set $cache_uri "null cache";
    }

    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 $nocache 1;
    set $cache_uri "null cache";
    }

    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
    set $nocache 1;
    set $cache_uri "null cache";
    }

    ##
    @@ -97,19 +97,19 @@ server {
    }

    ##
    # Deny access to version control repository metadata
    # Deny access to hidden files
    ##

    location ~ /\.(git|svn)/* {
    location ~ /\. {
    deny all;
    }

    ##
    # Deny access to hidden files
    # Deny access to uploaded PHP files
    ##

    location ~ \.(ht|gitignore$) {
    deny all;
    location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
    }

    ##
    @@ -136,34 +136,27 @@ server {
    location ~ \.php$ {
    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_intercept_errors on;
    fastcgi_read_timeout 300;
    # fastcgi_keep_conn on;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    # fastcgi_intercept_errors on;
    # fastcgi_keep_conn on;
    # fastcgi_read_timeout 300;

    if ($nocache = 0) {
    add_header X-Cache-Debug "$request_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
    }
    # fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    ##
    # FastCGI cache config
    ##

    # fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m;
    # fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:10m max_size=1000m inactive=60m;
    # fastcgi_cache_key $scheme$host$request_uri$request_method;
    # fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    fastcgi_no_cache $nocache;
    fastcgi_cache_bypass $nocache;
    fastcgi_cache microcache;
    fastcgi_cache_key $scheme$host$request_uri$request_method;
    fastcgi_cache_valid any 1m;
    fastcgi_cache_bypass $http_pragma;
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid any 30m;
    }
    }
  4. @goblindegook goblindegook revised this gist Feb 18, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -147,6 +147,7 @@ server {
    fastcgi_read_timeout 300;
    # fastcgi_keep_conn on;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    if ($nocache = 0) {
    add_header X-Cache-Debug "$request_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
  5. @goblindegook goblindegook revised this gist Feb 18, 2014. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -13,26 +13,27 @@ server {
    charset UTF-8;

    ##
    # gzip
    # gzip config
    ##

    gzip on;
    gzip_static on;
    gzip_vary on;
    gzip_disable "msie6";
    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;

    ##
    # Server logs
    # Server log config
    ##

    access_log off;
    error_log /path/to/logs/error.log error;
    error_log /path/to/logs/error.log warn;

    ##
    # FastCGI cache
    # FastCGI cache exceptions
    ##

    set $nocache 0;
    @@ -54,7 +55,7 @@ server {
    }

    ##
    # Browser cache
    # Browser cache config
    ##

    location ~ \.(css|htc|js|js2|js3|js4)$ {
  6. @goblindegook goblindegook revised this gist Feb 18, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -145,7 +145,6 @@ server {
    fastcgi_intercept_errors on;
    fastcgi_read_timeout 300;
    # fastcgi_keep_conn on;
    fastcgi_param SCRIPT_FILENAME /path/to/www$fastcgi_script_name;
    include fastcgi_params;

    if ($nocache = 0) {
  7. @goblindegook goblindegook revised this gist Feb 18, 2014. 1 changed file with 79 additions and 37 deletions.
    116 changes: 79 additions & 37 deletions wordpress.nginxconf
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,3 @@
    upstream php-fpm {
    server unix:/var/run/php5-fpm.sock;
    }

    server {
    listen 80;
    server_name www.example.com;
    @@ -16,58 +12,109 @@ server {
    index index.php;
    charset UTF-8;

    ##
    # gzip
    ##

    gzip on;
    gzip_static 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;

    ##
    # Server logs
    ##

    access_log off;
    error_log /path/to/logs/error.log error;

    ##
    # FastCGI cache
    ##

    set $nocache 0;

    if ($request_method = POST) {
    set $nocache 1;
    }

    if ($query_string != "") {
    set $nocache 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 $nocache 1;
    }

    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
    set $nocache 1;
    }

    ##
    # Browser cache
    ##

    location ~ \.(css|htc|js|js2|js3|js4)$ {
    expires 31536000s;
    expires max;
    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;
    expires max;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
    log_not_found off;
    }

    # Server logs
    access_log /path/to/logs/access.log;
    error_log /path/to/logs/error.log debug;

    # favicon

    ##
    # 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;
    }
    @@ -81,46 +128,41 @@ server {
    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;
    fastcgi_read_timeout 300;
    # fastcgi_keep_conn on;
    fastcgi_param SCRIPT_FILENAME /path/to/www$fastcgi_script_name;
    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;
    if ($nocache = 0) {
    add_header X-Cache-Debug "$request_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
    }

    ##
    # FastCGI cache config
    ##

    # fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m;
    fastcgi_no_cache $nocache;
    fastcgi_cache_bypass $nocache;
    fastcgi_cache microcache;
    fastcgi_cache_key $scheme$host$request_uri$request_method;
    fastcgi_cache_valid any 1m;
    fastcgi_cache_bypass $http_pragma;
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    }
    }
  8. @goblindegook goblindegook renamed this gist Feb 16, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @goblindegook goblindegook created this gist Feb 16, 2014.
    126 changes: 126 additions & 0 deletions gistfile1.nginxconf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@
    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;
    }
    }