default.conf 3.85 KB
Newer Older
Dave Lane's avatar
Dave Lane committed
1
2
3
# Caching configuration
# https://easyengine.io/wordpress-nginx/tutorials/multisite/subdirectories/fastcgi-cache-with-purging/
#
4
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:500m inactive=60m;
Dave Lane's avatar
Dave Lane committed
5
6
7
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;

8
9
10
11
12
13
14
15
16
17
# from https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
#
# using subdir approach, not subdomain...
map $uri $blogname{
	~^(?P<blogpath>/[^/]+/)files/(.*)  $blogpath ;
}

map $blogname $blogid{
	default -999;
	#Ref: http://wordpress.org/extend/plugins/nginx-helper/
Dave Lane's avatar
Dave Lane committed
18
	include /var/www/html/wp-content/uploads/nginx-helper/map.conf;
19
20
21
22
}

# statements for each of your virtual hosts to this file
server {
23
	listen 0.0.0.0:80;
24
25
26
    root /var/www/html;
	index index.php index.html index.htm;

Dave Lane's avatar
Dave Lane committed
27
28
29
30
31
    #
    # Caching configuration
    #
    #fastcgi_cache start
    set $skip_cache 0;
32

Dave Lane's avatar
Dave Lane committed
33
34
35
    # POST requests and urls with a query string should always go to PHP
	if ($request_method = POST) { set $skip_cache 1; }
	if ($query_string != "") { set $skip_cache 1; }
36

Dave Lane's avatar
Dave Lane committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    # 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 $skip_cache 1;
	}
	# Don't use the cache for logged in users or recent commenters
	if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
		set $skip_cache 1;
	}
    # end main Caching functionality

    #
    # Flow of serving pages
    #
	# from https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
51
52
53
54
55

   	#avoid php readfile()
    location ^~ /blogs.dir {
      	internal;
       	alias /var/www/html/wp-content/blogs.dir;
56
       	access_log off; log_not_found off; expires max;
57
58
    }

59
60
61
62
63
    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php) $2 last;
    }
64
65
66
67

  	# from https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04
    # with other bits from https://premium.wpmudev.org/blog/wordpress-multisite-wordpress-nginx/
    location / {
68
        try_files $uri $uri/ /index.php?$args;
69
70
71
72
73
    }
    error_page 404 /404.html;

    # Directives to send expires headers and turn off 404 error logging.
    location ~* ^.+\.(xml|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)$ {
74
        access_log off; log_not_found off; expires max;
75
76
77
    }

    location ~ \.php$ {
78
        try_files $uri =404;
79
        fastcgi_pass php:9000;
80
81
82
83
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_keep_conn on;
        fastcgi_index index.php;
        include fastcgi_params;
84
85
86
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_intercept_errors on;
87
88
89
90
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
Dave Lane's avatar
Dave Lane committed
91
92
93
94
95
96
        #
        # caching functionality
    	fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;
		fastcgi_cache WORDPRESS;
		fastcgi_cache_valid 60m;
97
    }
Dave Lane's avatar
Dave Lane committed
98
99
100
101
102
103
104
105
106
107
108
    #
    # caching functionality
	location ~ /purge(/.*) { fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";	}
    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { allow all; log_not_found off; access_log off; }
	location ~ ^(/[^/]+/)?files/(.+) {
        try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
        access_log off; log_not_found off; expires max;
    }


109
}