Skip to content

Instantly share code, notes, and snippets.

@thamaraiselvam
Created June 19, 2018 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thamaraiselvam/69fbadb929822136c64d4db7478259b0 to your computer and use it in GitHub Desktop.
Save thamaraiselvam/69fbadb929822136c64d4db7478259b0 to your computer and use it in GitHub Desktop.
Working Nginx + Multisite + localhost + linux configuration
server {
##DM - uncomment following line for domain mapping
#listen 80 default_server;
server_name dev.multisite.com;
##DM - uncomment following line for domain mapping
#server_name_in_redirect off;
# FORGE SSL (DO NOT REMOVE!)
# ssl on;
# ssl_certificate;
# ssl_certificate_key;
access_log /var/log/nginx/dev.multisite.com.access.log;
error_log /var/log/nginx/dev.multisite.com.error.log;
root /var/www/html/subdomains/multisite;
index index.php;
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'NULL';
}
if ($query_string != "") {
set $cache_uri 'NULL';
}
# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
set $cache_uri 'NULL';
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'NULL';
}
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
try_files /wp-content/cache/page_enhanced/${host}${cache_uri}_index.html $uri $uri/ /index.php?$args ;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 180;
include fastcgi.conf;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment