Configuration code
The code is as follows: |
Copy code |
Server { Listen 80; Server_name www.111cn.net 111cn.net; Access_log/data/logs/nginx/www.111cn.net. access. log main; Index index.html index. php; Root/data/site/www.111cn.net; Location /{ Try_files $ uri // index. php? $ Args; Add_header Pragma "public "; Expires 12 h; } Rewrite/wp-admin $ scheme: // $ host $ uri/permanent; Location ~ * ^. + \. (Ogg | ogv | svg | svgz | eot | otf | woff | mp4 | ttf | rss | atom | jpg | jpeg | gif | png | ico | zip | tgz | gz | rar | bz2 | doc | xls | exe | ppt | tar | mid | midi | wav | bmp | rtf) $ { Access_log off; Log_not_found off; Expires max; } Location ~ \. Php $ { Try_files $ uri = 404;
Fastcgi_split_path_info ^ (. + \. php) (/. +) $; # NOTE: You shoshould have "cgi. fix_pathinfo = 0;" in php. ini Include fastcgi_params; Fastcgi_index index. php; Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; # Fastcgi_intercept_errors on; Fastcgi_pass 127.0.0.1: 9000; } Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $ { Expires 24 h; Access_log off; } Location ~ . * \. (Js | css) $ { Expires 24 h; Access_log off; } |
Restart your nginx
Fixed Link (URL rewriting) rules in nginx
It is only used for a single WordPress site (usually installed by default), not multiple sites. Insert the following code into the root of location:
The code is as follows: |
Copy code |
If (! -F $ request_filename ){ Set $ rule_1 1 $ rule_1; } If (! -D $ request_filename ){ Set $ rule_1 2 $ rule_1; } If ($ rule_1 = "21 "){ Rewrite/./index. php last; }
|
My WordPress configuration in nginx:
The code is as follows: |
Copy code |
Location /{ Root html/xiedexu.cn; Index. php index.html index.htm; If (! -F $ request_filename ){ Set $ rule_1 1 $ rule_1; } If (! -D $ request_filename ){ Set $ rule_1 2 $ rule_1; } If ($ rule_1 = "21 "){ Rewrite/./index. php last; } Add_header Cache-Control private; } |
There are currently no errors in the new version, and there will be two rule warnings. Bo you @ the kitten wandering in May said it was the if trap of nginx and shared a new configuration scheme. The solution is comprehensive, but if your conf is not configured in that way, you only need to insert the following in location:
Try_files $ uri // index. php? $ Args;
WordPress Nginx redirection rules for your own use, suitable for non-subdirectory installation:
The code is as follows: |
Copy code |
Location /{ Try_files $ uri // index. php? $ Args; } Rewrite/wp-admin $ scheme: // $ host $ uri/permanent;
|
AMH comes with the following:
The code is as follows: |
Copy code |
Location /{ If (-f $ request_filename/index.html ){ Rewrite (. *) $1/index.html break; } If (-f $ request_filename/index. php ){ Rewrite (. *) $1/index. php; } If (! -F $ request_filename ){ Rewrite (. *)/index. php; } }
|
Simple usage: AMH uses the AMRewrite plug-in to create a Rewrite rule, validate the rule, edit the VM, and select the new rule.
Directly change nginx. conf to learn more about it. If you are not familiar with nginx, you will be paralyzed.