HansVanEijsden

Nginx vhost config

Jan 24th, 2017
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 5.27 KB | None | 0 0
  1. # HansVanEijsden WordPress Configuration - Redis FastCGI Page Cache Version
  2. server {
  3.  
  4.     listen   80; ## listen for ipv4; this line is default and implied
  5.     listen   [::]:80; ## listen for ipv6
  6.  
  7.     server_name www.danseressen.nl danseressen.nl;
  8.  
  9.         location /.well-known/acme-challenge {
  10.         alias /srv/www/acme-challenges/;
  11.         try_files $uri =404;
  12.         }
  13.  
  14.     location / {
  15.     return 301 https://$host$request_uri;
  16.     }
  17.  
  18. }
  19.  
  20.  
  21. server {
  22.  
  23.     listen  443 http2;
  24.     listen  [::]:443 http2;
  25.  
  26.     server_name www.danseressen.nl danseressen.nl;
  27.  
  28.     ssl_certificate /etc/letsencrypt/www.danseressen.nl/www.danseressen.nl.crt+chain;
  29.     ssl_certificate_key /etc/letsencrypt/www.danseressen.nl/www.danseressen.nl.key;
  30.  
  31.     ssl_stapling               on;
  32.     ssl_stapling_verify        on;
  33.     ssl_trusted_certificate /etc/letsencrypt/intermediate.pem;
  34.  
  35.     add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
  36.     add_header Public-Key-Pins 'pin-sha256="uYb387ter4w6YtmxDQZmSBjnCwSxMh1GfjnqvJkaBVk="; pin-sha256="9+Fks5ifH9WWgPrui/9/WonjiV8Y+4+J3TMxPjcPlTI="; pin-sha256="i/p24QLKIfUlHG+gtyO7bz1dIeY7d+9JsoRwrQ79lJo="; max-age=15768000; includeSubdomains';
  37.  
  38.     access_log   /var/log/nginx/danseressen.access.log main_ext;
  39.     error_log    /var/log/nginx/danseressen.error.log crit;
  40.  
  41.     root /home/danseressen/www;
  42.     index index.php index.htm index.html;
  43.  
  44.     add_header X-Frame-Options "SAMEORIGIN";
  45.  
  46. set $skip_cache 0;
  47.  
  48. # POST requests and URL with a query string should always go to php
  49. if ($request_method = POST) {
  50.     set $skip_cache 1;
  51. }
  52.  
  53. if ($query_string != "") {
  54.     set $skip_cache 1;
  55. }
  56.  
  57. # Don't cache URL containing the following segments
  58. if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
  59.     set $skip_cache 1;
  60. }
  61.  
  62. # Don't use the cache for logged in users or recent commenter
  63. if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
  64.     set $skip_cache 1;
  65. }
  66.  
  67. # Use cached or actual file if they exists, Otherwise pass request to WordPress
  68. location / {
  69.     try_files $uri $uri/ /index.php?$args;
  70. }
  71.  
  72.     location /redis-fetch {
  73.         internal  ;
  74.         set  $redis_key $args;
  75.         redis_pass  127.0.0.1:6379;
  76.     }
  77.  
  78.     location /redis-store {
  79.         internal  ;
  80.         set_unescape_uri $key $arg_key ;
  81.         redis2_query  set $key $echo_request_body;
  82.         redis2_query expire $key 14400;
  83.         redis2_pass  127.0.0.1:6379;
  84.     }
  85.  
  86. location ~ ^/wp-content/cache/minify/(.+\.(css|js))$ {
  87.     try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1;
  88. }
  89.  
  90. location ~ \.php$ {
  91.     set $key "www.danseressen.nl:$scheme$request_method$host$request_uri";
  92.     try_files $uri =404;
  93.  
  94.         srcache_fetch_skip $skip_cache;
  95.         srcache_store_skip $skip_cache;
  96.  
  97.         srcache_response_cache_control off;
  98.  
  99.         set_escape_uri $escaped_key $key;
  100.  
  101.         srcache_fetch GET /redis-fetch $key;
  102.         srcache_store PUT /redis-store key=$escaped_key;
  103.  
  104.         more_set_headers 'X-Cache $srcache_fetch_status';
  105.         more_set_headers 'X-Cache-2 $srcache_store_status';
  106.  
  107.     include fastcgi_params;
  108.     fastcgi_pass unix:/var/run/danseressen-php.sock;
  109.  
  110. }
  111.  
  112.  
  113. ##
  114. # WordPress Common Settings
  115. ##
  116.  
  117. # Limit access to avoid brute force attack
  118. location = /wp-login.php {
  119.     limit_req zone=one burst=1 nodelay;
  120.     include fastcgi_params;
  121.     fastcgi_pass unix:/var/run/danseressen-php.sock;
  122. }
  123.  
  124. # Disable wp-config.txt
  125. location = /wp-config.txt {
  126.     deny  all;
  127. #   access_log off;
  128. #   log_not_found off;
  129. }
  130.  
  131. # Disallow php in upload folder
  132. location /wp-content/uploads/ {
  133.     location ~ \.php$ {
  134.         #Prevent Direct Access Of PHP Files From Web Browsers
  135.         deny all;
  136.     }
  137. }
  138.  
  139. # Yoast sitemap
  140. location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
  141.     rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
  142.   rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
  143.     rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
  144.     rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
  145.  
  146.   # Following lines are options. Needed for WordPress seo addons
  147.   rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;
  148.     rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
  149.     rewrite ^/geo_sitemap\.xml$ /index.php?sitemap=wpseo_local last;
  150.     rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;
  151.  
  152. #   access_log off;
  153. }
  154.  
  155.  
  156. ##
  157. # Locations - Common Configuration
  158. ##
  159.  
  160. # Basic locations files
  161. location = /favicon.ico {
  162. #   access_log off;
  163. #   log_not_found off;
  164.     expires max;
  165. }
  166.  
  167. location = /robots.txt {
  168. #   access_log off;
  169. #   log_not_found off;
  170. }
  171.  
  172. # Cache static files
  173. location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf|webp)$ {
  174. #   access_log off;
  175. #   log_not_found off;
  176.     expires max;
  177.     add_header Access-Control-Allow-Origin *;
  178.     add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  179. }
  180.  
  181.  
  182. ##
  183. # Locations - Security Settings
  184. ##
  185.  
  186. # Deny hidden files
  187. location ~ /\. {
  188.     deny  all;
  189. #   access_log off;
  190. #   log_not_found off;
  191. }
  192.  
  193. # Deny backup extensions & log files
  194. location ~* ^.+\.(bak|log|old|orig|original|php#|php~|php_bak|save|swo|swp)$ {
  195.     deny  all;
  196. #   access_log off;
  197. #   log_not_found off;
  198. }
  199.  
  200. }
Advertisement
Add Comment
Please, Sign In to add comment