wordpress的nginx全部规则wordpress.conf(含伪静态)

www.365-588.com XKER.COM 时间:2017-07-17 21:23:24来源:www.365-588.com原创  评论:

普通站点规则:

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

多站点: 

  1. # WordPress multisite subdirectory rules. 
  2. # Designed to be included in any server {} block. 
  3.  
  4. map $uri $blogname{ 
  5.     ~^(?P<blogpath>/[^/]+/)files/(.*)       $blogpath ; 
  6.  
  7. map $blogname $blogid{ 
  8.     default -999; 
  9.  
  10.     #Ref: http://wordpress.org/extend/plugins/nginx-helper/ 
  11.     #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ; 
  12.  
  13. server { 
  14.     server_name example.com ; 
  15.  
  16.     root /var/www/example.com/htdocs; 
  17.     index index.php; 
  18.  
  19.     location ~ ^(/[^/]+/)?files/(.+) { 
  20.         try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ; 
  21.         access_log off;     log_not_found off; expires max; 
  22.     } 
  23.  
  24.     #avoid php readfile() 
  25.     location ^~ /blogs.dir { 
  26.         internal; 
  27.         alias /var/www/example.com/htdocs/wp-content/blogs.dir ; 
  28.         access_log off;     log_not_found off; expires max; 
  29.     } 
  30.  
  31.     if (!-e $request_filename) { 
  32.         rewrite /wp-admin$ $scheme://$host$uri/ permanent; 
  33.         rewrite ^(/[^/]+)?(/wp-.*) $2 last; 
  34.         rewrite ^(/[^/]+)?(/.*\.php) $2 last; 
  35.     } 
  36.  
  37.     location / { 
  38.         try_files $uri $uri/ /index.php?$args ; 
  39.     } 
  40.  
  41.     location ~ \.php$ { 
  42.         try_files $uri =404
  43.         include fastcgi_params; 
  44.         fastcgi_pass php; 
  45.     } 
  46.  
  47.     #add some rules for static content expiry-headers here 

本文来源:www.365-588.com原创

如果您喜欢本文请分享给您的好友,谢谢!如想浏览更多更好的建站程序内容,请登录:http://www.tootnn.com/edu/website/6/index.html