Last active
March 6, 2020 00:37
-
-
Save CKGrafico/b324ea7a10a7a024b3bb52c92d3a451c to your computer and use it in GitHub Desktop.
wordpress-nginx-azure
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
# Add custom rules | |
upstream php { | |
server unix:/var/run/php/php7.0-fpm.sock; | |
#server 127.0.0.1:9000; | |
} | |
# BEGIN fastcgi | |
fastcgi_cache_path /home/nginx-fastcgi-cache levels=1:2 keys_zone=BLOGWORDPRESS:100m inactive=60m; | |
#fastcgi_cache_key "$scheme$request_method$host$request_uri"; | |
#fastcgi_cache_use_stale error timeout invalid_header http_500; | |
#fastcgi_ignore_headers Cache-Control Expires Set-Cookie; | |
server { | |
listen 80; | |
## Your website name goes here. | |
server_name _; | |
## Your only path reference. | |
root /home/site/wwwroot; | |
## This should be in your http block and if it is, it's not needed here. | |
index index.php; | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
# Add locations of phpmyadmin here. | |
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html | |
sendfile off; | |
# cache by default | |
set $skip_cache 0; | |
# set default empty skip reason | |
set $skip_reason ""; | |
# POST requests and urls with a query string should always go to PHP | |
if ($request_method = POST) { | |
set $skip_cache 1; | |
set $skip_reason "${skip_reason}-POST"; | |
} | |
if ($query_string != "") { | |
set $skip_cache 1; | |
set $skip_reason "${skip_reason}-QueryString"; | |
} | |
# Don't cache uris containing the following segments | |
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { | |
set $skip_cache 1; | |
set $skip_reason "${skip_reason}-URI"; | |
} | |
# Don't use the cache for logged in users or recent commenters | |
#if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { | |
# set $skip_cache 1; | |
# set $skip_reason "${skip_reason}-Cookie"; | |
#} | |
location / { | |
# This is cool because no php is touched for static content. | |
# include the "?$args" part so non-default permalinks doesn't break when using query string | |
try_files $uri $uri/ /index.php?$args; | |
proxy_buffering on; | |
proxy_buffer_size 128k; | |
proxy_buffers 4 256k; | |
proxy_busy_buffers_size 256k; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
# add cache status | |
add_header Plain-Cache-Fastcgi-Cache $upstream_cache_status; | |
# add the cache skip reason if relevant | |
add_header Plain-Cache-Skip $skip_reason; | |
include fastcgi_params; | |
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; | |
fastcgi_split_path_info ^(.+\.php)(.*)$; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_cache_bypass $http_secret_header $skip_cache; | |
fastcgi_no_cache $skip_cache; | |
fastcgi_cache BLOGWORDPRESS; | |
fastcgi_cache_valid 404 1m; | |
fastcgi_cache_valid 60m; | |
fastcgi_buffer_size 128k; | |
fastcgi_buffers 4 256k; | |
fastcgi_busy_buffers_size 256k; | |
} | |
} | |
# END fastcgi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment