1- # You may add here your
2- # server {
3- # ...
4- # }
5- # statements for each of your virtual hosts to this file
6-
7- ##
8- # You should look at the following URL's in order to grasp a solid understanding
9- # of Nginx configuration files in order to fully unleash the power of Nginx.
10- # http://wiki.nginx.org/Pitfalls
11- # http://wiki.nginx.org/QuickStart
12- # http://wiki.nginx.org/Configuration
13- #
14- # Generally, you will want to move this file somewhere, and start with a clean
15- # file but keep this around for reference. Or just disable in sites-enabled.
16- #
17- # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
18- ##
19-
201server {
212 listen 80; ## listen for ipv4; this line is default and implied
223 listen [::]:80 default ipv6only=on; ## listen for ipv6
234
5+ charset UTF-8;
246 root /usr/share/nginx/www;
257 index index.php index.html index.htm;
268
27- # Make site accessible from http://localhost/
289 server_name localhost;
2910
3011 location / {
31- # First attempt to serve request as file, then
32- # as directory, then fall back to index.html
33- try_files $uri $uri/ /index.php?q=$uri&$args;
34- # Uncomment to enable naxsi on this location
35- # include /etc/nginx/naxsi.rules
12+ try_files $uri $uri/ @memcached;
3613 }
3714
38- location /doc/ {
39- alias /usr/share/doc/;
40- autoindex on;
41- allow 127.0.0.1;
42- allow ::1;
43- deny all;
15+ location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
16+ expires 24h;
17+ log_not_found off;
4418 }
4519
46- # Only for nginx-naxsi : process denied requests
47- #location /RequestDenied {
48- # For example, return an error code
49- #return 418;
50- #}
51-
52- #error_page 404 /404.html;
53-
5420 # redirect server error pages to the static page /50x.html
5521 #
5622 error_page 500 502 503 504 /50x.html;
@@ -60,63 +26,98 @@ server {
6026
6127 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
6228 #
63- location ~ \.php$ {
64- try_files $uri =404;
65- fastcgi_split_path_info ^(.+\.php)(/.+)$;
66- # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
67-
68- # With php5-cgi alone:
29+ location ~ (\.php) {
30+ try_files $uri =404;
31+ fastcgi_index index.php;
32+ fastcgi_connect_timeout 10;
33+ fastcgi_send_timeout 180;
34+ fastcgi_read_timeout 180;
35+ fastcgi_buffer_size 512k;
36+ fastcgi_buffers 4 256k;
37+ fastcgi_busy_buffers_size 512k;
38+ fastcgi_temp_file_write_size 512k;
39+ fastcgi_intercept_errors on;
40+ fastcgi_split_path_info ^(.+\.php)(/.*)$;
41+ fastcgi_keep_conn on;
42+
43+ fastcgi_param QUERY_STRING $query_string;
44+ fastcgi_param REQUEST_METHOD $request_method;
45+ fastcgi_param CONTENT_TYPE $content_type;
46+ fastcgi_param CONTENT_LENGTH $content_length;
47+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
48+ fastcgi_param SCRIPT_NAME $fastcgi_script_name;
49+ fastcgi_param REQUEST_URI $request_uri;
50+ fastcgi_param DOCUMENT_URI $document_uri;
51+ fastcgi_param DOCUMENT_ROOT $document_root;
52+ fastcgi_param SERVER_PROTOCOL $server_protocol;
53+ fastcgi_param GATEWAY_INTERFACE CGI/1.1;
54+ fastcgi_param SERVER_SOFTWARE nginx;
55+ fastcgi_param REMOTE_ADDR $remote_addr;
56+ fastcgi_param REMOTE_PORT $remote_port;
57+ fastcgi_param SERVER_ADDR $server_addr;
58+ fastcgi_param SERVER_PORT $server_port;
59+ fastcgi_param SERVER_NAME $server_name;
60+ fastcgi_param PATH_INFO $fastcgi_path_info;
61+ fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
62+ fastcgi_param REDIRECT_STATUS 200;
63+
64+ # uncomment these for HTTPS usage
65+ #fastcgi_param HTTPS $https if_not_empty;
66+ #fastcgi_param SSL_PROTOCOL $ssl_protocol if_not_empty;
67+ #fastcgi_param SSL_CIPHER $ssl_cipher if_not_empty;
68+ #fastcgi_param SSL_SESSION_ID $ssl_session_id if_not_empty;
69+ #fastcgi_param SSL_CLIENT_VERIFY $ssl_client_verify if_not_empty;
70+
6971 fastcgi_pass 127.0.0.1:9000;
70- # With php5-fpm:
71- # fastcgi_pass unix:/var/run/php5-fpm.sock;
72- fastcgi_index index.php;
73- include fastcgi_params;
7472 }
7573
76- # deny access to .htaccess files, if Apache's document root
77- # concurs with nginx's one
78- #
79- #location ~ /\.ht {
80- # deny all;
81- #}
82- }
74+ # try to get result from memcached
75+ location @memcached {
76+ default_type text/html;
77+ set $memcached_key data-$scheme://$host$request_uri;
78+ set $memcached_request 1;
79+
80+ # exceptions
81+ # avoid cache serve of POST requests
82+ if ($request_method = POST ) {
83+ set $memcached_request 0;
84+ }
85+
86+ # avoid cache serve of wp-admin-like pages, starting with "wp-"
87+ if ( $uri ~ "/wp-" ) {
88+ set $memcached_request 0;
89+ }
8390
91+ # avoid cache serve of any URL with query strings
92+ if ( $args ) {
93+ set $memcached_request 0;
94+ }
95+
96+
97+ if ($http_cookie ~* "comment_author_|wordpressuser_|wp-postpass_|wordpress_logged_in_" ) {
98+ set $memcached_request 0;
99+ }
100+
101+
102+
103+ if ( $memcached_request = 1) {
104+ add_header X-Cache-Engine "WP-FFPC with memcache via nginx";
105+ memcached_pass memcached-servers;
106+ error_page 404 = @rewrites;
107+ }
108+
109+ if ( $memcached_request = 0) {
110+ rewrite ^ /index.php last;
111+ }
112+ }
113+
114+ location @rewrites {
115+ add_header X-Cache-Engine "No cache";
116+ rewrite ^ /index.php last;
117+ }
118+
119+ }
84120
85- # another virtual host using mix of IP-, name-, and port-based configuration
86- #
87- #server {
88- # listen 8000;
89- # listen somename:8080;
90- # server_name somename alias another.alias;
91- # root html;
92- # index index.html index.htm;
93- #
94- # location / {
95- # try_files $uri $uri/ /index.html;
96- # }
97- #}
98-
99-
100- # HTTPS server
101- #
102- #server {
103- # listen 443;
104- # server_name localhost;
105- #
106- # root html;
107- # index index.html index.htm;
108- #
109- # ssl on;
110- # ssl_certificate cert.pem;
111- # ssl_certificate_key cert.key;
112- #
113- # ssl_session_timeout 5m;
114- #
115- # ssl_protocols SSLv3 TLSv1;
116- # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
117- # ssl_prefer_server_ciphers on;
118- #
119- # location / {
120- # try_files $uri $uri/ /index.html;
121- # }
122- #}
121+ upstream memcached-servers {
122+ server 127.0.0.1:11211;
123+ }
0 commit comments