WordPress Nginx 配置

WordPress 的 Nginx 配置示例。

 1# Upstream to abstract backend connection(s) for php
 2upstream php {
 3        server unix:/tmp/php-cgi.socket;
 4        server 127.0.0.1:9000;
 5}
 6    
 7server {
 8        ## Your website name goes here.
 9        server_name domain.tld;
10        ## Your only path reference.
11        root /var/www/wordpress;
12        ## This should be in your http block and if it is, it's not needed here.
13        index index.php;
14    
15        location = /favicon.ico {
16                log_not_found off;
17                access_log off;
18        }
19    
20        location = /robots.txt {
21                allow all;
22                log_not_found off;
23                access_log off;
24        }
25    
26        location / {
27                # This is cool because no php is touched for static content.
28                # include the "?$args" part so non-default permalinks doesn't break when using query string
29                try_files $uri $uri/ /index.php?$args;
30        }
31    
32        location ~ \.php$ {
33                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
34                include fastcgi.conf;
35                fastcgi_intercept_errors on;
36                fastcgi_pass php;
37        }
38    
39        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
40                expires max;
41                log_not_found off;
42        }
43}