{"id":48682,"date":"2020-03-09T14:47:06","date_gmt":"2020-03-09T06:47:06","guid":{"rendered":"http:\/\/4563.org\/?p=48682"},"modified":"2020-03-09T14:47:06","modified_gmt":"2020-03-09T06:47:06","slug":"%e6%b1%82nginx%e9%ab%98%e6%89%8b%e6%9d%a5%e6%8c%87%e5%af%bc%e4%b8%80%e4%b8%8bproxy_pass-proxy_redirect-rewrite%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=48682","title":{"rendered":"\u6c42nginx\u9ad8\u624b\u6765\u6307\u5bfc\u4e00\u4e0bproxy_pass proxy_redirect rewrite\u7684\u95ee\u9898"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>\u4f0a\u65af\u84dd<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u6c42nginx\u9ad8\u624b\u6765\u6307\u5bfc\u4e00\u4e0bproxy_pass proxy_redirect rewrite\u7684\u95ee\u9898<\/h3>\n<p>  \t\t# \u5b9a\u4e49\u53d8\u91cf<br \/>  &nbsp; &nbsp; map $http_upgrade $connection_upgrade {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;default upgrade;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8221;&nbsp; &nbsp;&nbsp; &nbsp;close;<br \/>  &nbsp; &nbsp; }<\/p>\n<p>  server<br \/>  {<br \/>  &nbsp; &nbsp; listen 80;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; listen 443 ssl http2;<br \/>  &nbsp; &nbsp; server_name aaa.com www.aaa.com;<br \/>  &nbsp; &nbsp; index index.php index.html index.htm default.php default.htm default.html;<br \/>  &nbsp; &nbsp; root \/www\/wwwroot\/aaa.com;<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; #SSL-START SSL\u76f8\u5173\u914d\u7f6e\uff0c\u8bf7\u52ff\u5220\u9664\u6216\u4fee\u6539\u4e0b\u4e00\u884c\u5e26\u6ce8\u91ca\u7684404\u89c4\u5219<br \/>  &nbsp; &nbsp; #error_page 404\/404.html;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; #301-START<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($host ~ &#8216;^aaa.com&#8217;){<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 301 http:\/\/www.aaa.com$request_uri;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; #301-END<br \/>  &nbsp; &nbsp; #HTTP_TO_HTTPS_START<br \/>  &nbsp; &nbsp; if ($server_port !~ 443){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;rewrite ^(\/.*)$ https:\/\/$host$1 permanent;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; #HTTP_TO_HTTPS_END<br \/>  &nbsp; &nbsp; ssl_certificate&nbsp; &nbsp; \/www\/server\/panel\/vhost\/cert\/aaa.com\/fullchain.pem;<br \/>  &nbsp; &nbsp; ssl_certificate_key&nbsp; &nbsp; \/www\/server\/panel\/vhost\/cert\/aaa.com\/privkey.pem;<br \/>  &nbsp; &nbsp; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;<br \/>  &nbsp; &nbsp; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;<br \/>  &nbsp; &nbsp; ssl_prefer_server_ciphers on;<br \/>  &nbsp; &nbsp; ssl_session_cache shared:SSL:10m;<br \/>  &nbsp; &nbsp; ssl_session_timeout 10m;<br \/>  &nbsp; &nbsp; error_page 497https:\/\/$host$request_uri;<\/p>\n<p>  &nbsp; &nbsp; #SSL-END<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; #ERROR-PAGE-START\u9519\u8bef\u9875\u914d\u7f6e\uff0c\u53ef\u4ee5\u6ce8\u91ca\u3001\u5220\u9664\u6216\u4fee\u6539<br \/>  &nbsp; &nbsp; #error_page 404 \/404.html;<br \/>  &nbsp; &nbsp; #error_page 502 \/502.html;<br \/>  &nbsp; &nbsp; #ERROR-PAGE-END<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; #PHP-INFO-STARTPHP\u5f15\u7528\u914d\u7f6e\uff0c\u53ef\u4ee5\u6ce8\u91ca\u6216\u4fee\u6539<br \/>  &nbsp; &nbsp; include enable-php-73.conf;<br \/>  &nbsp; &nbsp; #PHP-INFO-END<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; #REWRITE-START URL\u91cd\u5199\u89c4\u5219\u5f15\u7528,\u4fee\u6539\u540e\u5c06\u5bfc\u81f4\u9762\u677f\u8bbe\u7f6e\u7684\u4f2a\u9759\u6001\u89c4\u5219\u5931\u6548<br \/>  &nbsp; &nbsp; include \/www\/server\/panel\/vhost\/rewrite\/aaa.com.conf;<br \/>  &nbsp; &nbsp; #REWRITE-END<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; #\u7981\u6b62\u8bbf\u95ee\u7684\u6587\u4ef6\u6216\u76ee\u5f55<br \/>  &nbsp; &nbsp; location ~ ^\/(.user.ini|.htaccess|.git|.svn|.project|LICENSE|README.md)<br \/>  &nbsp; &nbsp; {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;return 404;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; #\u4e00\u952e\u7533\u8bf7SSL\u8bc1\u4e66\u9a8c\u8bc1\u76ee\u5f55\u76f8\u5173\u8bbe\u7f6e<br \/>  &nbsp; &nbsp; location ~ .well-known{<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;allow all;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$<br \/>  &nbsp; &nbsp; {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;expires&nbsp; &nbsp;&nbsp; &nbsp;30d;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;error_log off;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;access_log \/dev\/null;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; location ~ .*.(js|css)?$<br \/>  &nbsp; &nbsp; {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;expires&nbsp; &nbsp;&nbsp; &nbsp;12h;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;error_log off;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;access_log \/dev\/null; <br \/>  &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; #V2ray\u4ee3\u7406<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; location \/ {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;set $flag 0;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;#\u5982\u679c\u662fhttp\u8bbf\u95eev2ray\u7684\u4f2a\u88c5<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if ($scheme = http) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;set $flag 1;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;#\u5982\u679c\u662f\u641c\u7d22\u5f15\u64ce<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if ($http_user_agent ~* (baiduspider|soso|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;set $flag 2;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;#\u5982\u679c\u662f\u722c\u866b<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if ($http_user_agent ~* &quot;python|curl|java|wget|httpclient|okhttp&quot;) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;set $flag 2;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;#\u8fd4\u56de\u5230\u6307\u5b9a\u7684\u7f51\u7ad9\uff0c\u53ef\u4ee5\u662f\u81ea\u5df1\u7684\u7ad9\u70b9<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if ($flag = 1) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;rewrite ^\/(.*)$ http:\/\/www.bbb.com\/;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if ($flag = 2) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;rewrite ^\/(.*)$ http:\/\/www.bbb.com\/;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;#\u5982\u679c\u4e0d\u662fwebsocket\u8bf7\u6c42<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if ( $http_upgrade != &quot;websocket&quot; ) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;rewrite ^\/(.*)$ https:\/\/www.bbb.com\/;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_redirect off;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_pass http:\/\/127.0.0.1:56789;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_http_version 1.1;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_set_header Upgrade $http_upgrade;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_set_header Connection &quot;upgrade&quot;;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_set_header Host $http_host;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;proxy_read_timeout 300s;<br \/>  &nbsp; &nbsp; }<br \/>  #&nbsp; &nbsp; location \/ {<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;proxy_redirect off;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;proxy_http_version 1.1;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;proxy_set_header Upgrade $http_upgrade;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;proxy_set_header Connection &quot;upgrade&quot;;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;proxy_set_header Host $http_host;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;proxy_intercept_errors on;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if ($http_upgrade = &quot;websocket&quot; ){<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;proxy_pass http:\/\/127.0.0.1:56789;<br \/>  #&nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  #&nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; access_log\/www\/wwwlogs\/aaa.com.log;<br \/>  &nbsp; &nbsp; error_log\/www\/wwwlogs\/aaa.com.error.log;<br \/>  }<\/p>\n<p>  \u4e0a\u9762\u662f\u5b9d\u5854\u7684\u7ad9\u70b9\u914d\u7f6e\u6587\u4ef6<br \/>  v2ray+ws+tls\u5df2\u7ecf\u6b63\u5e38<br \/>  \u6d4f\u89c8\u5668\u6253\u5f00aaa.com\u7684\u65f6\u5019\u4f1a\u8f6c\u5411\u5230bbb.com<br \/>  \u8bf7\u95ee\u8be5\u600e\u4e48\u4fee\u6539\u624d\u80fd\u5b9e\u73b0\u53cd\u4ee3bbb.com\u7684\u6548\u679c<br \/>  \u5c31\u662f\u5730\u5740\u680f\u663e\u793aaaa.com<br \/>  \u7f51\u7ad9\u91cc\u9762\u7684\u94fe\u63a5\u4e5f\u5168\u90fd\u662faaa.com\u7684\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f0a\u65af\u84dd \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u6c42ngin&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/48682"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48682"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/48682\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48682"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}