方式一,写死地址,用变量
最简洁
map $scheme $online_proxy_www {
default 39.156.66.10;
}
proxy_pass $scheme://$online_proxy_www:$server_port;
方式二,写两个upstream,再用proxy_pass覆盖法
缺点需要维护2个upsteam
upstream online_proxy_www {
server 39.156.66.10:80;
}
upstream online_proxy_www_https {
server 39.156.66.10:443;
}
proxy_pass $scheme://online_proxy_www;
自适应https
if ( $scheme = https) {
proxy_pass $scheme://online_proxy_www_https;
}
方式三,upstream backup法
最简单,缺点会多一次请求,多个错误日志
upstream online_proxy_www {
server 39.156.66.10:80;39.156.66.10
server 39.156.66.10:443 backup;
}
proxy_pass $scheme://online_proxy_www;
==========================
nginx.conf示例
upstream online_proxy_www {
server 39.156.66.10:80;
#server 39.156.66.10:443 backup;
}
upstream online_proxy_www_https {
server 39.156.66.10:443;
}
server
{
listen 80;
listen 443 ssl;
server_name blog.c1gstudio.com;
index index.html index.htm index.php;
root /opt/htdocs/www;
access_log /var/log/nginx/blog.c1gstudio.com.log access ;
include ssl.conf;
location /
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxypass_forwarded_for;
proxy_pass $scheme://$online_proxy_www:$server_port;
add_header X-Cache C1GPROXY1;
}
}
No Responses (yet)
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.