iT邦幫忙

0

Nginx 對應hotsname的問題

用nginx做對應多網站
abc.test.com.tw可以正常
cde.test.com.tw卻出現502 Bad Gateway
請問以下設定哪邊會有問題嗎

vip 192.168.100.190
nginx 192.168.100.191
192.168.100.192

nginx.conf
upstream abc_pool{
ip_hash;
server 192.168.100.20:443 weight=4 max_fails=2 fail_timeout=30s;
server 192.168.100.21:443 weight=4 max_fails=2 fail_timeout=30s;
}

upstream cde_pool{
    server 192.168.100.30:443 weight=4 max_fails=2 fail_timeout=30s;
    server 192.168.100.31:443 weight=4 max_fails=2 fail_timeout=30s;
}
include /etc/nginx/conf.d/*.conf;

/conf.d/default.conf
##ABC設定
server {
listen 80;
server_name abc.test.com.tw;
rewrite ^(.*) https://$host$1 permanent;
return 301 https://$host$request_uri;
location / {
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass https://abc_pool;
}
}

server {
listen 443 ssl;
server_name abc.test.com.tw;
location / {
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass https://abc_pool;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

##CDE設定
server {
listen 80;
server_name cde.goldennet.com.tw;
rewrite ^(.*) https://$host$1 permanent;
return 301 https://$host$request_uri;
location / {
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass https://cde_pool;
}
}

server {
listen 443 ssl;
server_name cde.goldennet.com.tw;
location / {
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_pass https://cde_pool;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

新二君 iT邦新手 2 級 ‧ 2020-01-05 22:26:25 檢舉
我不太清楚是不是你兩個域名的port都設定80和443關係,但如國能nginx -t通過因該是沒有問題才對

尚未有邦友回答

立即登入回答