Advertisement
Guest User

example.com nginx config

a guest
Nov 10th, 2017
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 2.89 KB | None | 0 0
  1. server {
  2.     listen 80;
  3.  
  4.     server_name example.com www.example.com;
  5.  
  6.     location / {
  7.         rewrite ^/sub1/?(.*)$ https://sub1.example.com/$1 permanent;
  8.         rewrite ^/sub2/?(.*)$ https://sub2.example.com/$1 permanent;
  9.         rewrite ^/sub3/?(.*)$ https://sub3.example.com/$1 permanent;
  10.         rewrite ^/sub4/?(.*)$ https://sub4.example.com/$1 permanent;
  11.         return 301 https://$host$request_uri;
  12.     }
  13. }
  14.  
  15.  
  16. server {
  17.     listen 443 ssl;
  18.  
  19.     root /var/www/example.com;
  20.     index index.php index.html index.htm;
  21.  
  22.     server_name example.com www.example.com;
  23.  
  24.     access_log /var/log/nginx/example.com.access.log;
  25.     error_log  /var/log/nginx/example.com.error.log;
  26.  
  27.     include snippets/ssl-example.conf;
  28.     include snippets/ssl-params.conf;
  29.  
  30.     set $cache_uri $request_uri;
  31.  
  32.     # POST requests and URLs with a query string should always go to PHP
  33.     if ($request_method = POST) {
  34.         set $cache_uri 'null cache';
  35.     }
  36.     if ($query_string != "") {
  37.         set $cache_uri 'null cache';
  38.     }
  39.  
  40.     # Don't cache URIs containing the following segments
  41.     if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php
  42.                          |wp-.*.php|/feed/|index.php|wp-comments-popup.php
  43.                          |wp-links-opml.php|wp-locations.php |sitemap(_index)?.xml
  44.                          |[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
  45.  
  46.         set $cache_uri 'null cache';
  47.     }
  48.  
  49.     # Don't use the cache for logged-in users or recent commenters
  50.     if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+
  51.                         |wp-postpass|wordpress_logged_in") {
  52.         set $cache_uri 'null cache';
  53.     }
  54.  
  55.     # Use cached or actual file if it exists, otherwise pass request to WordPress
  56.     location / {
  57.         rewrite ^/sub1/?(.*)$ https://sub1.example.com/$1 permanent;
  58.         rewrite ^/sub2/?(.*)$ https://sub2.example.com/$1 permanent;
  59.         rewrite ^/sub3/?(.*)$ https://sub3.example.com/$1 permanent;
  60.         rewrite ^/sub4/?(.*)$ https://sub4.example.com/$1 permanent;
  61.         try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html
  62.         $uri $uri/ /index.php;
  63.     }
  64.  
  65.     location ~ .php$ {
  66.         try_files $uri /index.php;
  67.         include fastcgi_params;
  68.         fastcgi_pass unix:/var/run/php5-fpm.sock;
  69.         fastcgi_index index.php;
  70.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  71.     }
  72.  
  73.     location = /favicon.ico {
  74.         log_not_found off;
  75.         access_log off;
  76.     }
  77.  
  78.     location = /robots.txt {
  79.         log_not_found off;
  80.         access_log off;
  81.     }
  82.  
  83.     # Cache static files for as long as possible
  84.     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)$ {
  85.         expires max;
  86.         log_not_found off;
  87.         access_log off;
  88.    }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement