在 Google Compute Instance 上打开 443?

ccl*_*oyd 6 https port-forwarding google-compute-engine gcloud

出于某种原因,我无法在我的 google 计算实例上打开端口 443。我在实例上启用了 HTTPS 服务器,使用gcloud compute firewall-rules list返回以下规则:

NAME                    NETWORK  DIRECTION  PRIORITY  ALLOW                         DENY
default-allow-http      default  INGRESS    1000      tcp:80
default-allow-https     default  INGRESS    1000      tcp:443
default-allow-icmp      default  INGRESS    65534     icmp
default-allow-internal  default  INGRESS    65534     tcp:0-65535,udp:0-65535,icmp
default-allow-rdp       default  INGRESS    65534     tcp:3389
default-allow-ssh       default  INGRESS    65534     tcp:22
Run Code Online (Sandbox Code Playgroud)

然而,当我使用类似nmap它说它已关闭的东西检查端口是否打开时。

PORT     STATE  SERVICE
22/tcp   open   ssh
443/tcp  closed https
Run Code Online (Sandbox Code Playgroud)

编辑:这是该站点的我的 nginx conf 文件。 https://gist.github.com/cclloyd/e7f1183f3a018dbc32cd7c55e15375cf

小智 5

检查应用程序是否正在运行

您需要检查是否确实有一个应用程序在您的实例上运行,该应用程序正在侦听 443 端口。

sudo netstat -plnt
Run Code Online (Sandbox Code Playgroud)

例如,如果有 nginx 服务正在运行,并且配置为监听 443 端口,你会看到类似这样的内容

Proto Local Address           Foreign Address         State       PID/Program name
tcp   0.0.0.0:443             0.0.0.0:*               LISTEN      2742/nginx -g daemo
Run Code Online (Sandbox Code Playgroud)

检查防火墙规则关联

您还可以检查您的防火墙规则和您的实例是否具有适当的标签:

检查防火墙规则目标标签:

$ gcloud compute firewall-rules describe default-allow-https --format="value(targetTags)"
Run Code Online (Sandbox Code Playgroud)

应该输出“https-server”

检查实例标签:

$ gcloud compute instances describe %INSTANCE_NAME% --format="value(tags.items)"
Run Code Online (Sandbox Code Playgroud)

也应该输出“https-server”。