Last active
December 25, 2022 15:55
-
-
Save markjaquith/04162825d159c8fb5534 to your computer and use it in GitHub Desktop.
My WordPress Nginx setup
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 phpfpm { | |
server unix:/var/run/php5-fpm.sock; | |
} | |
upstream hhvm { | |
server unix:/var/run/hhvm/hhvm.sock; | |
} | |
# SSL | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS; | |
ssl_buffer_size 8k; | |
spdy_headers_comp 6; | |
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache_fpm:30m max_size=1000m; |
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; | |
<% if @use_ssl %> | |
listen 443 ssl spdy; | |
ssl_certificate ssl/<%= @domain %>/server.crt; | |
ssl_certificate_key ssl/<%= @domain %>/server.key; | |
<% end %> | |
server_name <%= @domain %><% if @also_www %> www.<%= @domain %><% end %>; | |
access_log /var/log/nginx/access.log main; | |
root /srv/www/<%= @path %>; | |
index index.html index.htm index.php; | |
include sites-available/custom/<%= @domain %>; | |
location ~ \.(jpe?g|gif|png|css|bmp|js|ico)$ { | |
expires 30d; | |
} | |
location / { | |
try_files $uri $uri/ /index.php$is_args$args; | |
} | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /var/www/nginx-default; | |
} | |
location ~ /\.ht[a-z]+$ { | |
deny all; | |
} | |
location ~ \.php$ { | |
# Set some proxy cache stuff | |
fastcgi_cache microcache_fpm; | |
fastcgi_cache_key $scheme$host$request_method$request_uri; | |
fastcgi_cache_valid 200 5s; | |
fastcgi_cache_use_stale updating; | |
fastcgi_max_temp_file_size 1M; | |
fastcgi_cache_min_uses 3; # Hit a URL 3 times before caching it | |
set $no_cache_set 0; | |
set $no_cache_get 0; | |
set $temp_caching_exemption 0; | |
if ($request_method !~ ^(GET|HEAD)$) { | |
set $temp_caching_exemption 1; | |
} | |
if ( $temp_caching_exemption = 1 ) { | |
add_header Set-Cookie "_mcnc=1; Max-Age=10; Path=/"; | |
} | |
# Bypass cache if no-cache cookie is set | |
if ( $http_cookie ~* "_mcnc" ) { | |
set $no_cache_set 1; | |
set $no_cache_get 1; | |
} | |
if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) { | |
set $no_cache_set 1; | |
set $no_cache_get 1; | |
} | |
# fastcgi_no_cache means "Do not store this proxy response in the cache" | |
fastcgi_no_cache $no_cache_set; | |
# fastcgi_cache_bypass means "Do not look in the cache for this request" | |
fastcgi_cache_bypass $no_cache_get; | |
include /etc/nginx/fastcgi_params; | |
fastcgi_index index.php; | |
try_files $uri =404; | |
<% if @hhvm %> | |
fastcgi_keep_conn on; | |
fastcgi_pass hhvm; | |
<% else %> | |
fastcgi_pass phpfpm; | |
<% end %> | |
} | |
} |
Thanks for this.
You know you can have a block that falls back from HHVM to PHP-FPM? Quite a nice trick ;D
Thanks in a lot.
Is this in front of Apache? Or are you just running wordpress on nginx with mysql standalone?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What are the prerequisites on a Ununtu 14.04 Server?
Thanks in advance :)