Windows 无法使用 public IP 地址访问 VM

Windows VM is not accessible with public ip address

我有 azure windows server 2016 虚拟机,我已经在 运行 php 网站上安装了 nginx 服务器。它是 运行 私有 IP 地址和本地主机,但不能使用 public IP 地址。

我在入站端口规则中启用了端口 80

我的 nginx 配置是:

server {
    listen       <my public IP>:80;
    location / {
        root   html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  C:/nginx-1.14.0/html$fastcgi_script_name;
        include        fastcgi_params;
    }
}

首先,你可以这样修改nginx的配置文件:

server {
    listen      80;
    server_name example.org www.example.org(not ip address);
    ...
    }

然后您可以在虚拟机上使用命令netstat -a检查80端口是否正在侦听。另外,看看虚拟机端的防火墙配置中是否开启了80端口

完成上述步骤后,在客户端上使用 telnet publicipaddress 80 验证网络连接是否正常。

如果telnet结果正常,您可以尝试运行 php IP地址为public的网站

更多参考,请参考How nginx processes a request