Nginx无法实现HTTPS转HTTP重定向且API访问报错的问题求助
Nginx无法实现HTTPS转HTTP重定向且API访问报错的问题求助
我最近在实现HTTPS到HTTP的重定向时遇到了大麻烦,已经折腾好几天了,完全摸不着头绪 😩
场景说明
我有一个托管在独立虚拟主机上的网站,还有一台VPS服务器,上面部署了只能通过HTTP访问的API。比如正常的curl调用应该是这样的:
curl http://xxx.xxx.xx.xx:4000/foo/bar
VPS上安装了Nginx,当前的配置文件如下:
server { listen <website-domain-ip>:443; server_name localhost <website-domain> www.<website-domain>; ssl_certificate /root/certificates/<website-domain>/certificate.crt; ssl_certificate_key /root/certificates/<website-domain>/private.key; location ~ / { proxy_pass http://127.0.0.1:4000; } } # server { # listen 80; # server_name <website-domain> www.<website-domain>; # return 301 http://$http_host$request_uri; # }
报错情况
当我尝试访问API时,浏览器抛出错误:
Failed to load resource: net::ERR_CONNECTION_REFUSED
完整的错误信息是:
GET https://xxx.xxx.xx.xxx:4000/foo/bar net::ERR_CONNECTION_REFUSED
已尝试的操作
我试过调整多种Nginx配置,主要是修改listen参数(比如只监听443)或者调整SSL相关设置。我猜测问题大概率出在listen配置上(可能还有其他问题,但这应该是第一个卡点)。
另外,Nginx的access.log和error.log都是空的,这说明根本没有建立连接,应该是listen的配置有问题。我完全控制SSL证书,拥有cert、ca_bundle和private key文件。
有没有大佬能帮我解决这个问题?
更新信息
curl命令输出
执行curl -IL https://example.com/foo/bar的完整输出:
curl: (35) error:0A00010B:SSL routines::wrong version number
VPS进程监听情况
执行lsof -i得到的运行进程:
systemd-n 690 systemd-network 15u IPv4 853475 0t0 UDP ip185-132-47-xxx.pbiaas.com:bootpc systemd-r 692 systemd-resolve 13u IPv4 24956 0t0 UDP localhost:domain systemd-r 692 systemd-resolve 14u IPv4 24957 0t0 TCP localhost:domain (LISTEN) sshd 744 root 3u IPv4 24330 0t0 TCP *:ssh (LISTEN) sshd 744 root 4u IPv6 24332 0t0 TCP *:ssh (LISTEN) postgres 782 postgres 5u IPv6 31871 0t0 TCP localhost:postgresql (LISTEN) postgres 782 postgres 6u IPv4 31872 0t0 TCP localhost:postgresql (LISTEN) postgres 782 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 postgres 788 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 postgres 789 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 postgres 790 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 postgres 791 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 postgres 792 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 postgres 793 postgres 8u IPv6 31877 0t0 UDP localhost:60421->localhost:60421 nginx 35874 root 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35874 root 7u IPv4 647927 0t0 TCP *:http (LISTEN) nginx 35875 www-data 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35875 www-data 7u IPv4 647927 0t0 TCP *:http (LISTEN) nginx 35876 www-data 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35876 www-data 7u IPv4 647927 0t0 TCP *:http (LISTEN) nginx 35877 www-data 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35877 www-data 7u IPv4 647927 0t0 TCP *:http (LISTEN) nginx 35878 www-data 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35878 www-data 7u IPv4 647927 0t0 TCP *:http (LISTEN) nginx 35879 www-data 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35879 www-data 7u IPv4 647927 0t0 TCP *:http (LISTEN) nginx 35880 www-data 6u IPv4 647926 0t0 TCP *:https (LISTEN) nginx 35880 www-data 7u IPv4 647927 0t0 TCP *:http (LISTEN) sshd 47034 root 4u IPv4 854019 0t0 TCP ip185-132-47-xxx.pbiaas.com:ssh->148-216-099-087.dynamic.<internet-provider>.<country-code>:55102 (ESTABLISHED) sshd 47257 root 4u IPv4 853604 0t0 TCP ip185-132-47-xxx.pbiaas.com:ssh->119.96.159.237:54986 (ESTABLISHED)
备注:内容来源于stack exchange,提问作者J_P
相关产品推荐
相关产品推荐

