{"id":283,"date":"2015-11-13T09:15:08","date_gmt":"2015-11-13T09:15:08","guid":{"rendered":"http:\/\/blog.yyhcw.com\/post\/283.html"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T07:54:17","slug":"nginx_rewrite","status":"publish","type":"post","link":"http:\/\/blog.yyhcw.com\/post\/283.html","title":{"rendered":"LNMP\uff08Linux+Nginx+MySQL+php\uff09\u4f2a\u9759\u6001rewrite\u89c4\u5219\u8be6\u89e3"},"content":{"rendered":"<p>\u6700\u8fd1\u5728VPS\u4e0a\u5c1d\u8bd5\u914d\u7f6e\u5b89\u88c5\u4e00\u4e2a\u7f51\u7ad9\uff0cVPS\u5b89\u88c5\u4e86LNMP\uff08Linux+Nginx+MySQL+php\uff09\u5728\u914d\u7f6e\u91cd\u5b9a\u89c4\u5219\u7684\u65f6\u5019\u7ecf\u5e38\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u76f4\u63a5\u7528Apache\u7684\u89c4\u5219\u5230Nginx\u4e0b\u6ca1\u8d77\u4f5c\u7528\u3002\u539f\u6765Apache \u91cd\u5199\u7684\u89c4\u5219\u5230nginx\u4e0a\u8fd8\u6709\u4e00\u4e9b\u4e0d\u592a\u4e00\u6837\u7684\u5730\u65b9\u3002<em>\u8fd9\u7bc7\u6587\u7ae0\u662f\u76f4\u63a5\u8f6c\u8fc7\u6765\u7684 \u7559\u4ee5\u540e\u5907\u7528\uff01<\/em><\/p>\n<p>\u8fd9\u91cc\u53ea\u662f\u7b80\u5355\u8bb0\u5f55\u4e00\u4e9b\u5b66\u4e60\u793a\u4f8b\uff0c\u9ad8\u624b\u7565\u8fc7\uff0c\u65b0\u624b\u53ef\u4ee5\u770b\u4e00\u4e0b\u3002<\/p>\n<p>Nginx Rewrite\u89c4\u5219\u76f8\u5173\u6307\u4ee4&nbsp;<\/p>\n<p>Nginx Rewrite\u89c4\u5219\u76f8\u5173\u6307\u4ee4\u6709if\u3001rewrite\u3001set\u3001return\u3001break\u7b49\uff0c\u5176\u4e2drewrite\u662f\u6700\u5173\u952e\u7684\u6307\u4ee4\u3002\u4e00\u4e2a\u7b80\u5355\u7684Nginx Rewrite\u89c4\u5219\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><\/p>\n<p>rewrite ^\/b\/(.*)\\.html \/play.php?video=$1 break;<\/p>\n<p><\/p>\n<p>\u5982\u679c\u52a0\u4e0aif\u8bed\u53e5\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p><\/p>\n<p>if (!-f $request_filename)<\/p>\n<p><\/p>\n<p>rewrite ^\/img\/(.*)$ \/site\/$host\/images\/$1 last;<\/p>\n<p><\/p>\n<p>Nginx\u4e0eApache\u7684Rewrite\u89c4\u5219\u5b9e\u4f8b\u5bf9\u6bd4<\/p>\n<p><\/p>\n<p>\u7b80\u5355\u7684Nginx\u548cApache \u91cd\u5199\u89c4\u5219\u533a\u522b\u4e0d\u5927\uff0c\u57fa\u672c\u4e0a\u80fd\u591f\u5b8c\u5168\u517c\u5bb9\u3002\u4f8b\u5982\uff1a<\/p>\n<p><\/p>\n<p>Apache Rewrite \u89c4\u5219\uff1a<\/p>\n<p><\/p>\n<p>RewriteRule ^\/(mianshi|xianjing)\/$ \/zl\/index.php?name=$1 [L]<\/p>\n<p><\/p>\n<p>RewriteRule ^\/ceshi\/$ \/zl\/ceshi.php [L]<\/p>\n<p><\/p>\n<p>RewriteRule ^\/(mianshi)_([a-zA-Z]+)\/$ \/zl\/index.php?name=$1_$2 [L]<\/p>\n<p><\/p>\n<p>RewriteRule ^\/pingce([0-9]*)\/$ \/zl\/pingce.php?id=$1 [L]<\/p>\n<p><\/p>\n<p>Nginx Rewrite \u89c4\u5219\uff1a<\/p>\n<p><\/p>\n<p>rewrite ^\/(mianshi|xianjing)\/$ \/zl\/index.php?name=$1 last;<\/p>\n<p><\/p>\n<p>rewrite ^\/ceshi\/$ \/zl\/ceshi.php last;<\/p>\n<p><\/p>\n<p>rewrite ^\/(mianshi)_([a-zA-Z]+)\/$ \/zl\/index.php?name=$1_$2 last;<\/p>\n<p><\/p>\n<p>rewrite ^\/pingce([0-9]*)\/$ \/zl\/pingce.php?id=$1 last;<\/p>\n<p><\/p>\n<p>\u7531\u4ee5\u4e0a\u793a\u4f8b\u53ef\u4ee5\u770b\u51fa\uff0cApache\u7684Rewrite\u89c4\u5219\u6539\u4e3aNginx\u7684Rewrite\u89c4\u5219\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\uff1aApache\u7684RewriteRule\u6307\u4ee4\u6362\u6210Nginx\u7684rewrite\u6307\u4ee4\uff0cApache\u7684[L]\u6807\u8bb0\u6362\u6210Nginx\u7684last\u6807\u8bb0\uff0c\u4e2d\u95f4\u7684\u5185\u5bb9\u4e0d\u53d8\u3002<\/p>\n<p><\/p>\n<p>\u5982\u679cApache\u7684Rewrite\u89c4\u5219\u6539\u4e3aNginx\u7684Rewrite\u89c4\u5219\u540e\uff0c\u4f7f\u7528nginx -t\u547d\u4ee4\u68c0\u67e5\u53d1\u73b0nginx.conf\u914d\u7f6e\u6587\u4ef6\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u90a3\u4e48\u53ef\u4ee5\u5c1d\u8bd5\u7ed9\u6761\u4ef6\u52a0\u4e0a\u5f15\u53f7\u3002\u4f8b\u5982\u4e00\u4e0b\u7684Nginx Rewrite\u89c4\u5219\u4f1a\u62a5\u8bed\u6cd5\u9519\u8bef\uff1a<\/p>\n<p><\/p>\n<p>rewrite ^\/([0-9]{5}).html$ \/x.jsp?id=$1 last;<\/p>\n<p><\/p>\n<p>\u52a0\u4e0a\u5f15\u53f7\u5c31\u6b63\u786e\u4e86\uff1a<\/p>\n<p>rewrite \u201c^\/([0-9]{5}).html$\u201d \/x.jsp?id=$1 last;<\/p>\n<p><\/p>\n<p>Apache\u4e0eNginx\u7684Rewrite\u89c4\u5219\u5728URL\u8df3\u8f6c\u65f6\u6709\u7ec6\u5fae\u7684\u533a\u522b\uff1a<\/p>\n<p><\/p>\n<p>Apache Rewrite \u89c4\u5219\uff1a<\/p>\n<p>RewriteRule ^\/html\/tagindex\/([a-zA-Z]+)\/.*$ \/$1\/ [R=301,L]<\/p>\n<p><\/p>\n<p>Nginx Rewrite \u89c4\u5219\uff1a<\/p>\n<p>rewrite ^\/html\/tagindex\/([a-zA-Z]+)\/.*$ http:\/\/$host\/$1\/ permanent;<\/p>\n<p><\/p>\n<p>\u4ee5\u4e0a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u6ce8\u610f\u5230\uff0cNginx Rewrite \u89c4\u5219\u7684\u7f6e\u6362\u4e32\u4e2d\u589e\u52a0\u4e86\u201chttp:\/\/$host\u201d\uff0c\u8fd9\u662f\u5728Nginx\u4e2d\u8981\u6c42\u7684\u3002<\/p>\n<p><\/p>\n<p>\u53e6\u5916\uff0cApache\u4e0eNginx\u7684Rewrite\u89c4\u5219\u5728\u53d8\u91cf\u540d\u79f0\u65b9\u9762\u4e5f\u6709\u533a\u522b\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><\/p>\n<p>Apache Rewrite \u89c4\u5219\uff1a<\/p>\n<p>RewriteRule ^\/user\/login\/$ \/user\/login.php?login=1&amp;forward=http:\/\/%{HTTP_HOST} [L]<\/p>\n<p><\/p>\n<p>Nginx Rewrite \u89c4\u5219\uff1a<\/p>\n<p>rewrite ^\/user\/login\/$ \/user\/login.php?login=1&amp;forward=http:\/\/$host &nbsp; last;<\/p>\n<p><\/p>\n<p>Apache\u4e0eNginx Rewrite \u89c4\u5219\u7684\u4e00\u4e9b\u529f\u80fd\u76f8\u540c\u6216\u7c7b\u4f3c\u7684\u6307\u4ee4\u3001\u6807\u8bb0\u5bf9\u5e94\u5173\u7cfb\uff1a<\/p>\n<p><\/p>\n<p>Apache\u7684RewriteCond\u6307\u4ee4\u5bf9\u5e94Nginx\u7684if\u6307\u4ee4\uff1b<\/p>\n<p>Apache\u7684RewriteRule\u6307\u4ee4\u5bf9\u5e94Nginx\u7684rewrite\u6307\u4ee4\uff1b<\/p>\n<p>Apache\u7684[R]\u6807\u8bb0\u5bf9\u5e94Nginx\u7684redirect\u6807\u8bb0\uff1b<\/p>\n<p>Apache\u7684[P]\u6807\u8bb0\u5bf9\u5e94Nginx\u7684last\u6807\u8bb0\uff1b<\/p>\n<p>Apache\u7684[R,L]\u6807\u8bb0\u5bf9\u5e94Nginx\u7684redirect\u6807\u8bb0\uff1b<\/p>\n<p>Apache\u7684[P,L]\u6807\u8bb0\u5bf9\u5e94Nginx\u7684last\u6807\u8bb0\uff1b<\/p>\n<p>Apache\u7684[PT,L]\u6807\u8bb0\u5bf9\u5e94Nginx\u7684last\u6807\u8bb0\uff1b<\/p>\n<p><\/p>\n<p>\u5141\u8bb8\u6307\u5b9a\u7684\u57df\u540d\u8bbf\u95ee\u672c\u7ad9\uff0c\u5176\u4ed6\u57df\u540d\u4e00\u5f8b\u8df3\u8f6c\u5230http:\/\/www.aaa.com<\/p>\n<p><\/p>\n<p>Apache Rewrite \u89c4\u5219\uff1a<\/p>\n<p>RewriteCond %{HTTP_HOST} &nbsp; &nbsp;^(.*?)\\.domain\\.com$<\/p>\n<p>RewriteCond %{HTTP_HOST} &nbsp; &nbsp;!^qita\\.domain\\.com$<\/p>\n<p>RewriteCond %{DOCUMENT_ROOT}\/market\/%1\/index.htm -f<\/p>\n<p>RewriteRule ^\/wu\/$ \/market\/%1\/index.htm [L]<\/p>\n<p><\/p>\n<p>Nginx\u7684if\u6307\u4ee4\u4e0d\u652f\u6301\u5d4c\u5957\uff0c\u4e5f\u4e0d\u652f\u6301AND\u3001OR\u7b49\u591a\u6761\u4ef6\u5339\u914d\uff0c\u76f8\u6bd4\u4e8eApache\u7684RewriteCond\uff0c\u663e\u5f97\u9ebb\u70e6\u4e00\u4e9b\uff0c\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u4e00\u9875\u7684Nginx\u914d\u7f6e\u5199\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e2a\u793a\u4f8b\uff1a<\/p>\n<p><\/p>\n<p>Nginx Rewrite \u89c4\u5219\uff1a<\/p>\n<p>if ($host ~* ^(.*?)\\.domain\\.com$) set $var_wupin_city $1;<\/p>\n<p>&nbsp; &nbsp; &nbsp;set $var_wupin \u20181\u2032;<\/p>\n<p><\/p>\n<p>if ($host ~* ^qita\\.domain\\.com$)<\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; set $var_wupin \u20180\u2032;<\/p>\n<p><\/p>\n<p>&nbsp;if (!-f $document_root\/market\/$var_wupin_city\/index.htm)<\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; &nbsp;set $var_wupin \u20180\u2032;<\/p>\n<p><\/p>\n<p>if ($var_wupin ~ \u20181\u2032)<\/p>\n<p><\/p>\n<p>&nbsp; &nbsp; rewrite ^\/wu\/$ \/market\/$var_wupin_city\/index.htm last;<\/p>\n<p>}<\/p>\n<p><\/p>\n<p>rewrite \u7684\u8bed\u6cd5<\/p>\n<p><\/p>\n<p>\u8bed\u6cd5: rewrite regex replacement flag<\/p>\n<p><\/p>\n<p>\u9ed8\u8ba4: none<\/p>\n<p><\/p>\n<p>\u4f5c\u7528\u57df: server, location, if<\/p>\n<p><\/p>\n<p>This directive changes URI in accordance with the regular expression and the replacement string. Directives are carried out in order of appearance in the configuration file.<\/p>\n<p><\/p>\n<p>\u8fd9\u4e2a\u6307\u4ee4\u6839\u636e\u8868\u8fbe\u5f0f\u6765\u66f4\u6539URI\uff0c\u6216\u8005\u4fee\u6539\u5b57\u7b26\u4e32\u3002\u6307\u4ee4\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u987a\u5e8f\u6765\u6267\u884c\u3002<\/p>\n<p><\/p>\n<p>Be aware that the rewrite regex only matches the relative path instead of the absolute URL. If you want to match the hostname, you should use an if condition, like so:<\/p>\n<p><\/p>\n<p>\u6ce8\u610f\u91cd\u5199\u8868\u8fbe\u5f0f\u53ea\u5bf9\u76f8\u5bf9\u8def\u5f84\u6709\u6548\u3002\u5982\u679c\u4f60\u60f3\u914d\u5bf9\u4e3b\u673a\u540d\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528if\u8bed\u53e5\u3002<\/p>\n<p><\/p>\n<p>rewrite\u53ea\u662f\u4f1a\u6539\u5199\u8def\u5f84\u90e8\u5206\u7684\u4e1c\u4e1c\uff0c\u4e0d\u4f1a\u6539\u52a8\u7528\u6237\u7684\u8f93\u5165\u53c2\u6570\uff0c\u56e0\u6b64\u8fd9\u91cc\u7684if\u89c4\u5219\u91cc\u9762\uff0c\u4f60\u65e0\u9700\u5173\u5fc3\u7528\u6237\u5728\u6d4f\u89c8\u5668\u91cc\u8f93\u5165\u7684\u53c2\u6570\uff0crewrite\u540e\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7684\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u53ea\u662f\u52a0\u4e0a\u4e86\u4e00\u4e2a\uff1f\u53f7\u548c\u540e\u9762\u6211\u4eec\u60f3\u8981\u7684\u4e00\u4e2a\u5c0f\u5c0f\u7684\u53c2\u6570 ***https=1\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p><\/p>\n<p>nginx\u7684rewrite\u89c4\u5219\u53c2\u8003\uff1a<\/p>\n<p><\/p>\n<p>~ \u4e3a\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d<\/p>\n<p>~* \u4e3a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d<\/p>\n<p>!~\u548c!~*\u5206\u522b\u4e3a\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d\u53ca\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339<\/p>\n<p>-f\u548c!-f\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u6587\u4ef6<\/p>\n<p>-d\u548c!-d\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u76ee\u5f55<\/p>\n<p>-e\u548c!-e\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u6587\u4ef6\u6216\u76ee\u5f55<\/p>\n<p>-x\u548c!-x\u7528\u6765\u5224\u65ad\u6587\u4ef6\u662f\u5426\u53ef\u6267\u884c<\/p>\n<p>last \u76f8\u5f53\u4e8eApache\u91cc\u7684[L]\u6807\u8bb0\uff0c\u8868\u793a\u5b8c\u6210rewrite\uff0c\u5475\u5475\u8fd9\u5e94\u8be5\u662f\u6700\u5e38\u7528\u7684<\/p>\n<p>break \u7ec8\u6b62\u5339\u914d, \u4e0d\u518d\u5339\u914d\u540e\u9762\u7684\u89c4\u5219<\/p>\n<p>redirect \u8fd4\u56de302\u4e34\u65f6\u91cd\u5b9a\u5411 \u5730\u5740\u680f\u4f1a\u663e\u793a\u8df3\u8f6c\u540e\u7684\u5730\u5740<\/p>\n<p>permanent \u8fd4\u56de301\u6c38\u4e45\u91cd\u5b9a\u5411 \u5730\u5740\u680f\u4f1a\u663e\u793a\u8df3\u8f6c\u540e\u7684\u5730\u5740<\/p>\n<p>$args<\/p>\n<p>$content_length<\/p>\n<p>$content_type<\/p>\n<p>$document_root<\/p>\n<p>$document_uri<\/p>\n<p>$host<\/p>\n<p>$http_user_agent<\/p>\n<p>$http_cookie<\/p>\n<p>$limit_rate<\/p>\n<p>$request_body_file<\/p>\n<p>$request_method<\/p>\n<p>$remote_addr<\/p>\n<p>$remote_port<\/p>\n<p>$remote_user<\/p>\n<p>$request_filename<\/p>\n<p>$request_uri<\/p>\n<p>$query_string<\/p>\n<p>$scheme<\/p>\n<p>$server_protocol<\/p>\n<p>$server_addr<\/p>\n<p>$server_name<\/p>\n<p>$server_port<\/p>\n<p>$uri<\/p>\n<p>\u7ed3\u5408QeePHP\u7684\u4f8b\u5b50<\/p>\n<p><\/p>\n<p>if (!-d $request_filename) {<\/p>\n<p>rewrite ^\/([a-z-A-Z]+)\/([a-z-A-Z]+)\/?(.*)$ \/index.php?namespace=user&amp;amp;controller=$1&amp;amp;action=$2&amp;amp;$3 last;<\/p>\n<p>rewrite ^\/([a-z-A-Z]+)\/?$ \/index.php?namespace=user&amp;amp;controller=$1 last;<\/p>\n<p>break;<\/p>\n<p>\u591a\u76ee\u5f55\u8f6c\u6210\u53c2\u6570<\/p>\n<p>abc.domian.com\/sort\/2 =&gt; abc.domian.com\/index.php?act=sort&amp;name=abc&amp;id=2<\/p>\n<p><\/p>\n<p>if ($host ~* (.*)\\.domain\\.com) {<\/p>\n<p>set $sub_name $1;<\/p>\n<p>rewrite ^\/sort\\\/(\\d+)\\\/?$ \/index.php?act=sort&amp;cid=$sub_name&amp;id=$1 last;<\/p>\n<p>}<\/p>\n<p>\u76ee\u5f55\u5bf9\u6362<\/p>\n<p>\/123456\/xxxx -&gt; \/xxxx?id=123456<\/p>\n<p><\/p>\n<p>rewrite ^\/(\\d+)\/(.+)\/ \/$2?id=$1 last;<\/p>\n<p>\u4f8b\u5982\u4e0b\u9762\u8bbe\u5b9anginx\u5728\u7528\u6237\u4f7f\u7528ie\u7684\u4f7f\u7528\u91cd\u5b9a\u5411\u5230\/nginx-ie\u76ee\u5f55\u4e0b\uff1a<\/p>\n<p><\/p>\n<p>if ($http_user_agent ~ MSIE) {<\/p>\n<p>rewrite ^(.*)$ \/nginx-ie\/$1 break;<\/p>\n<p>}<\/p>\n<p>\u76ee\u5f55\u81ea\u52a8\u52a0\u201c\/\u201d<\/p>\n<p><\/p>\n<p>if (-d $request_filename){<\/p>\n<p>rewrite ^\/(.*)([^\/])$ http:\/\/$host\/$1$2\/ permanent;<\/p>\n<p>}<\/p>\n<p>\u7981\u6b62htaccess<\/p>\n<p><\/p>\n<p>location ~\/\\.ht {<\/p>\n<p>deny all;<\/p>\n<p>}<\/p>\n<p>\u7981\u6b62\u591a\u4e2a\u76ee\u5f55<\/p>\n<p><\/p>\n<p>location ~ ^\/(cron|templates)\/ {<\/p>\n<p>deny all;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>\u7981\u6b62\u4ee5\/data\u5f00\u5934\u7684\u6587\u4ef6<\/p>\n<p>\u53ef\u4ee5\u7981\u6b62\/data\/\u4e0b\u591a\u7ea7\u76ee\u5f55\u4e0b.log.txt\u7b49\u8bf7\u6c42;<\/p>\n<p><\/p>\n<p>location ~ ^\/data {<\/p>\n<p>deny all;<\/p>\n<p>}<\/p>\n<p>\u7981\u6b62\u5355\u4e2a\u76ee\u5f55<\/p>\n<p>\u4e0d\u80fd\u7981\u6b62.log.txt\u80fd\u8bf7\u6c42<\/p>\n<p><\/p>\n<p>location \/searchword\/cron\/ {<\/p>\n<p>deny all;<\/p>\n<p>}<\/p>\n<p>\u7981\u6b62\u5355\u4e2a\u6587\u4ef6<\/p>\n<p><\/p>\n<p>location ~ \/data\/sql\/data.sql {<\/p>\n<p>deny all;<\/p>\n<p>}<\/p>\n<p>\u7ed9favicon.ico\u548crobots.txt\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4;<\/p>\n<p>\u8fd9\u91cc\u4e3afavicon.ico\u4e3a99\u5929,robots.txt\u4e3a7\u5929\u5e76\u4e0d\u8bb0\u5f55404\u9519\u8bef\u65e5\u5fd7<\/p>\n<p><\/p>\n<p>location ~(favicon.ico) {<\/p>\n<p>log_not_found off;<\/p>\n<p>expires 99d;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p><\/p>\n<p>location ~(robots.txt) {<\/p>\n<p>log_not_found off;<\/p>\n<p>expires 7d;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>\u8bbe\u5b9a\u67d0\u4e2a\u6587\u4ef6\u7684\u8fc7\u671f\u65f6\u95f4;\u8fd9\u91cc\u4e3a600\u79d2\uff0c\u5e76\u4e0d\u8bb0\u5f55\u8bbf\u95ee\u65e5\u5fd7<\/p>\n<p><\/p>\n<p>location ^~ \/html\/scripts\/loadhead_1.js {<\/p>\n<p>access_log &nbsp; off;<\/p>\n<p>root \/opt\/lampp\/htdocs\/web;<\/p>\n<p>expires 600;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>\u6587\u4ef6\u53cd\u76d7\u94fe\u5e76\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<\/p>\n<p>\u8fd9\u91cc\u7684return 412 \u4e3a\u81ea\u5b9a\u4e49\u7684http\u72b6\u6001\u7801\uff0c\u9ed8\u8ba4\u4e3a403\uff0c\u65b9\u4fbf\u627e\u51fa\u6b63\u786e\u7684\u76d7\u94fe\u7684\u8bf7\u6c42<\/p>\n<p>\u201crewrite ^\/ http:\/\/leech.divmy.com\/leech.gif;\u201d\u663e\u793a\u4e00\u5f20\u9632\u76d7\u94fe\u56fe\u7247<\/p>\n<p>\u201caccess_log off;\u201d\u4e0d\u8bb0\u5f55\u8bbf\u95ee\u65e5\u5fd7\uff0c\u51cf\u8f7b\u538b\u529b<\/p>\n<p>\u201cexpires 3d\u201d\u6240\u6709\u6587\u4ef63\u5929\u7684\u6d4f\u89c8\u5668\u7f13\u5b58<\/p>\n<p><\/p>\n<p>location ~* ^.+\\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {<\/p>\n<p>valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;<\/p>\n<p>if ($invalid_referer) {<\/p>\n<p>rewrite ^\/ http:\/\/leech.divmy.com\/leech.gif;<\/p>\n<p>return 412;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>access_log &nbsp; off;<\/p>\n<p>root \/opt\/lampp\/htdocs\/web;<\/p>\n<p>expires 3d;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>\u53ea\u5145\u8bb8\u56fa\u5b9aip\u8bbf\u95ee\u7f51\u7ad9\uff0c\u5e76\u52a0\u4e0a\u5bc6\u7801<\/p>\n<p><\/p>\n<p>root &nbsp;\/opt\/htdocs\/www;<\/p>\n<p>allow &nbsp; 208.97.167.194;<\/p>\n<p>allow &nbsp; 222.33.1.2;<\/p>\n<p>allow &nbsp; 231.152.49.4;<\/p>\n<p>deny &nbsp; &nbsp;all;<\/p>\n<p>auth_basic \u201cC1G_ADMIN\u201d;<\/p>\n<p>auth_basic_user_file htpasswd;<\/p>\n<p>\u5c06\u591a\u7ea7\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u8f6c\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u589e\u5f3aseo\u6548\u679c<\/p>\n<p>\/job-123-456-789.html \u6307\u5411\/job\/123\/456\/789.html<\/p>\n<p><\/p>\n<p>rewrite ^\/job-([0-9]+)-([0-9]+)-([0-9]+)\\.html$ \/job\/$1\/$2\/jobshow_$3.html last;<\/p>\n<p>\u5c06\u6839\u76ee\u5f55\u4e0b\u67d0\u4e2a\u6587\u4ef6\u5939\u6307\u54112\u7ea7\u76ee\u5f55<\/p>\n<p>\u5982\/shanghaijob\/ \u6307\u5411 \/area\/shanghai\/<\/p>\n<p>\u5982\u679c\u4f60\u5c06last\u6539\u6210permanent\uff0c\u90a3\u4e48\u6d4f\u89c8\u5668\u5730\u5740\u680f\u663e\u662f\/location\/shanghai\/<\/p>\n<p><\/p>\n<p>rewrite ^\/([0-9a-z]+)job\/(.*)$ \/area\/$1\/$2 last;<\/p>\n<p>\u4e0a\u9762\u4f8b\u5b50\u6709\u4e2a\u95ee\u9898\u662f\u8bbf\u95ee\/shanghai \u65f6\u5c06\u4e0d\u4f1a\u5339\u914d<\/p>\n<p><\/p>\n<p>rewrite ^\/([0-9a-z]+)job$ \/area\/$1\/ last;<\/p>\n<p>rewrite ^\/([0-9a-z]+)job\/(.*)$ \/area\/$1\/$2 last;<\/p>\n<p>\u8fd9\u6837\/shanghai \u4e5f\u53ef\u4ee5\u8bbf\u95ee\u4e86\uff0c\u4f46\u9875\u9762\u4e2d\u7684\u76f8\u5bf9\u94fe\u63a5\u65e0\u6cd5\u4f7f\u7528\uff0c<\/p>\n<p>\u5982.\/list_1.html\u771f\u5b9e\u5730\u5740\u662f\/area\/shanghia\/list_1.html\u4f1a\u53d8\u6210\/list_1.html,\u5bfc\u81f3\u65e0\u6cd5\u8bbf\u95ee\u3002<\/p>\n<p><\/p>\n<p>\u90a3\u6211\u52a0\u4e0a\u81ea\u52a8\u8df3\u8f6c\u4e5f\u662f\u4e0d\u884c\u54af<\/p>\n<p>(-d $request_filename)\u5b83\u6709\u4e2a\u6761\u4ef6\u662f\u5fc5\u9700\u4e3a\u771f\u5b9e\u76ee\u5f55\uff0c\u800c\u6211\u7684rewrite\u4e0d\u662f\u7684\uff0c\u6240\u4ee5\u6ca1\u6709\u6548\u679c<\/p>\n<p><\/p>\n<p>if (-d $request_filename){<\/p>\n<p>rewrite ^\/(.*)([^\/])$ http:\/\/$host\/$1$2\/ permanent;<\/p>\n<p>}<\/p>\n<p>\u77e5\u9053\u539f\u56e0\u540e\u5c31\u597d\u529e\u4e86\uff0c\u8ba9\u6211\u624b\u52a8\u8df3\u8f6c\u5427<\/p>\n<p><\/p>\n<p>rewrite ^\/([0-9a-z]+)job$ \/$1job\/ permanent;<\/p>\n<p>rewrite ^\/([0-9a-z]+)job\/(.*)$ \/area\/$1\/$2 last;<\/p>\n<p>\u6587\u4ef6\u548c\u76ee\u5f55\u4e0d\u5b58\u5728\u7684\u65f6\u5019\u91cd\u5b9a\u5411\uff1a<\/p>\n<p><\/p>\n<p>if (!-e $request_filename) {<\/p>\n<p>proxy_pass http:\/\/127.0.0.1;<\/p>\n<p>}<\/p>\n<p><\/p>\n<p>\u7ed9discuz\u67d0\u7248\u5757\u5355\u72ec\u914d\u7f6e\u57df\u540d<\/p>\n<p><\/p>\n<p>server_name &nbsp;blog.yyhcw.com shop.21863.cn;<\/p>\n<p><\/p>\n<p>location = \/ {<\/p>\n<p>if ($http_host ~ shop\\.21863.cn$) {<\/p>\n<p>rewrite ^.+ http:\/\/shop.21863.cn\/forum-831-1.html last;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>discuz ucenter \u5934\u50cf rewrite \u4f18\u5316<\/p>\n<p><\/p>\n<p>location ^~ \/ucenter {<\/p>\n<p>location ~ .*\\.php?$<\/p>\n<p>{<\/p>\n<p>#fastcgi_pass &nbsp;unix:\/tmp\/php-cgi.sock;<\/p>\n<p>fastcgi_pass &nbsp;127.0.0.1:9000;<\/p>\n<p>fastcgi_index index.php;<\/p>\n<p>include fcgi.conf;<\/p>\n<p>}<\/p>\n<p><\/p>\n<p>location \/ucenter\/data\/avatar {<\/p>\n<p>log_not_found off;<\/p>\n<p>access_log &nbsp; off;<\/p>\n<p>location ~ \/(.*)_big\\.jpg$ {<\/p>\n<p>error_page 404 \/ucenter\/images\/noavatar_big.gif;<\/p>\n<p>}<\/p>\n<p>location ~ \/(.*)_middle\\.jpg$ {<\/p>\n<p>error_page 404 \/ucenter\/images\/noavatar_middle.gif;<\/p>\n<p>}<\/p>\n<p>location ~ \/(.*)_small\\.jpg$ {<\/p>\n<p>error_page 404 \/ucenter\/images\/noavatar_small.gif;<\/p>\n<p>}<\/p>\n<p>expires 300;<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>jspace rewrite<\/p>\n<p><\/p>\n<p>location ~ .*\\.php?$<\/p>\n<p>{<\/p>\n<p>#fastcgi_pass &nbsp;unix:\/tmp\/php-cgi.sock;<\/p>\n<p>fastcgi_pass &nbsp;127.0.0.1:9000;<\/p>\n<p>fastcgi_index index.php;<\/p>\n<p>include fcgi.conf;<\/p>\n<p>}<\/p>\n<p><\/p>\n<p>location ~* ^\/index.php\/<\/p>\n<p>{<\/p>\n<p>rewrite ^\/index.php\/(.*) \/index.php?$1 break;<\/p>\n<p>fastcgi_pass &nbsp;127.0.0.1:9000;<\/p>\n<p>fastcgi_index index.php;<\/p>\n<p>include fcgi.conf;<\/p>\n<p>}<\/p>\n<p>\u53e6\u5916\u8fd9\u91cc\u8fd8\u6709\u4e00\u4e2a\u5de5\u5177\u53ef\u4ee5\u76f4\u63a5\u628aapache\u89c4\u5219\u8f6c\u5316\u4e3anginx\u89c4\u5219<\/p>\n<p><\/p>\n<p>http:\/\/www.anilcetin.com\/convert-apache-htaccess-to-nginx\/<\/p>\n<p><\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><\/p>\n<p>http:\/\/wiki.nginx.org\/NginxChsHttpRewriteModule<\/p>\n<p><\/p>\n<p>http:\/\/blog.csdn.net\/cnbird2008\/archive\/2009\/08\/04\/4409620.aspx<\/p>\n<p><\/p>\n<p>http:\/\/www.cnblogs.com\/cgli\/archive\/2011\/05\/16\/2047920.html<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"\u6700\u8fd1\u5728VPS\u4e0a\u5c1d\u8bd5\u914d\u7f6e\u5b89\u88c5\u4e00\u4e2a\u7f51\u7ad9\uff0cVPS\u5b89\u88c5\u4e86LNMP\uff08Linux+Nginx+MySQL+php\uff09\u5728\u914d\u7f6e\u91cd \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"views":279,"_links":{"self":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts\/283"}],"collection":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/comments?post=283"}],"version-history":[{"count":0,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts\/283\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}