Created
July 26, 2016 12:40
-
-
Save alexandcote/96463d98638fd18bd5890dd90e5460ac to your computer and use it in GitHub Desktop.
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 { | |
{% if item.value.ssl is defined and item.value.ssl.enabled | default(false) -%} | |
listen 443 ssl http2; | |
{% else -%} | |
listen 80; | |
{% endif %} | |
server_name {% for host in item.value.site_hosts %} {{ host | reverse_www(append=false) }} {% if item.value.multisite.subdomains | default(false) %} *.{{ host }} {% endif %} {% endfor %}; | |
access_log {{ www_root }}/{{ item.key }}/logs/access.log; | |
error_log {{ www_root }}/{{ item.key }}/logs/error.log; | |
root {{ www_root }}/{{ item.key }}/current/web; | |
index index.php index.htm index.html; | |
charset utf-8; | |
{% if env == 'development' -%} | |
# See Virtualbox section at http://wiki.nginx.org/Pitfalls | |
sendfile off; | |
{%- endif %} | |
{% if item.value.multisite.enabled | default(false) -%} | |
{% if item.value.multisite.subdomains | default(false) -%} | |
rewrite ^/(wp-.*.php)$ /wp/$1 last; | |
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last; | |
{%- else -%} | |
include wordpress_multisite_subdirectories.conf; | |
{%- endif %} | |
{%- endif %} | |
add_header Fastcgi-Cache $upstream_cache_status; | |
{% if item.value.ssl is defined and item.value.ssl.enabled | default(false) -%} | |
{{ lookup('template', 'https.conf.j2') }} | |
{% endif %} | |
include includes.d/{{ item.key }}/*.conf; | |
include wordpress.conf; | |
location ~ \.php$ { | |
try_files $uri =404; | |
error_page 404 /index.php; | |
{% if item.value.cache is defined and item.value.cache.enabled | default(false) -%} | |
set $skip_cache 0; | |
if ($query_string != "") { | |
set $skip_cache 1; | |
} | |
# Don't cache uris containing the following segments | |
if ($request_uri ~* "{{ item.value.cache.skip_cache_uri | default(nginx_skip_cache_uri) }}") { | |
set $skip_cache 1; | |
} | |
# Don't use the cache if cookies includes the following | |
if ($http_cookie ~* "{{ item.value.cache.skip_cache_cookie | default(nginx_skip_cache_cookie) }}") { | |
set $skip_cache 1; | |
} | |
fastcgi_cache wordpress; | |
fastcgi_cache_valid {{ item.value.cache.duration | default(nginx_cache_duration) }}; | |
fastcgi_cache_bypass $skip_cache; | |
fastcgi_no_cache $skip_cache; | |
{% endif -%} | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
fastcgi_param DOCUMENT_ROOT $realpath_root; | |
fastcgi_pass unix:/var/run/php-fpm-wordpress.sock; | |
} | |
} | |
{% if item.value.ssl is defined and item.value.ssl.enabled | default(false) %} | |
server { | |
listen 80; | |
server_name {{ item.value.site_hosts | reverse_www(enabled=item.value.www_redirect | default(true)) | join(' ') }}; | |
{% if item.value.ssl.provider | default('manual') == 'letsencrypt' -%} | |
include acme-challenge-location.conf; | |
location / { | |
return 301 https://$host$request_uri; | |
} | |
{% else %} | |
return 301 https://$host$request_uri; | |
{% endif -%} | |
} | |
{% endif %} | |
{% for host in item.value.site_hosts if item.value.www_redirect | default(true) %} | |
server { | |
{% if item.value.ssl is defined and item.value.ssl.enabled | default(false) -%} | |
listen 443 ssl http2; | |
{{ lookup('template', 'https.conf.j2') }} | |
{% else -%} | |
listen 80; | |
{% endif -%} | |
server_name {{ host }}; | |
return 301 $scheme://{{ host | reverse_www(append=false) }}$request_uri; | |
} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment