一、http反代
用1.com反代2.com
server { listen 80; server_name 1.com www.1.com; location / { proxy_pass http://2.com; proxy_set_header Host 2.com; proxy_set_header X-Forwarded-For $remote_addr; proxy_cache_key 2.com$request_uri$is_args$args; proxy_cache_valid 200 304 301 302 1h; add_header X-Cache $upstream_cache_status; proxy_set_header Accept-Encoding ""; sub_filter "2.com" "1.com"; sub_filter_once off; expires 12h; } location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$ { proxy_set_header Host 2.com; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://2.com; proxy_set_header Accept-Encoding ""; sub_filter "2.com" "1.com"; sub_filter_once off; } access_log /root/log/1.com.log; }
二、https反代(未测试)
用https://1.com反代http://2.com
server { listen 443 ssl http2; server_name 1.com www.1.com; index index.html index.htm index.php default.html default.htm default.php; ssl on; ssl_certificate /root/ssl/1.com.crt; ssl_certificate_key /root/ssl/1.com.key; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security "max-age=31536000"; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE; ssl_session_cache builtin:1000 shared:SSL:10m; resolver 8.8.4.4 8.8.8.8 valid=300s; resolver_timeout 10s; location / { proxy_pass http://2.com; proxy_set_header Host 2.com; proxy_set_header X-Forwarded-For $remote_addr; proxy_cache_key 2.com$request_uri$is_args$args; proxy_cache_valid 200 304 301 302 1h; add_header X-Cache $upstream_cache_status; proxy_set_header Accept-Encoding ""; sub_filter "2.com" "1.com"; sub_filter_once off; expires 12h; } location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$ { proxy_set_header Host 2.com; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://2.com; proxy_set_header Accept-Encoding ""; sub_filter "2.com" "1.com"; sub_filter_once off; } server { listen 80; server_name 1.com www.1.com; return 301 https://1.com$request_uri; }
文章来源于LOC论坛,原文地址:http://www.hostloc.com/thread-407992-3-4.html
文章评论