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

多站点: 

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

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

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