我为我的网站配置了Nginx反向代理,并尝试将所有请求从端口80重定向到端口443.首先,我认为我从http到https重定向的配置工作正常,因为我通过键入http://example.com进行了测试在Firefox和Chrome中都将请求重定向到https://example.com。但是,很少有朋友告诉我重定向失败了。因此我通过curl再次测试了同样的东西,这给了我结果:
curl: (7) Failed to connect to example.com port 80: Connection refused
然后我在我的机器上执行了netstat,我获得了以下结果。
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 13257/nginx -g daem
tcp6 0 0 :::443 :::* LISTEN 13257/nginx -g daem
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13257/nginx -g daem
tcp6 0 0 :::80 :::* LISTEN 13257/nginx -g daem
从结果来看,似乎nginx正在侦听端口80.然而,当我对我的机器执行nmap时。返回的结果nmap似乎端口80以某种方式关闭。
PORT STATE SERVICE
80/tcp closed http
443/tcp open https
这是我的nginx conf文件。
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
...
我真的不知道为什么端口80会关闭所以任何帮助都会非常感激!