在 Google Cloud Platform Cloud Shell 中创建 nginx 服务器

在 Google Cloud Platform Cloud Shell 中创建 nginx 服务器

我开始使用 Google Cloud Platform,作为我的第一次尝试,我在 Cloud Shell(而不是 Compute Engine 虚拟机)中安装并配置了一个 nginx 服务器

当我尝试:

卷曲http://127.0.0.1:8080

我得到一个:

curl:(7)无法连接到 127.0.0.1 端口 8080:连接被拒绝

我的问题是:在仪表板中 Cloud Shell 中的 Web 服务器(重要提示:我没有尝试新的 Compute Engine 虚拟机)或者这是可能的,只是我没有正确配置 nginx?(我刚刚添加了一个包含最少信息的 status.conf 文件,它可以在我的 Linux 中立即运行)

答案1

尽管通常不会使用 Cloud Shell 来执行您要执行的操作,但是没有什么可以阻止您运行 nginx 并从 Cloud Shell 内部访问它。

安装 nginx 后,请确保它正在运行并记下端口。Nginx 默认使用端口 80,因此请尝试在该端口上使用 curl。

这是我的云壳的输出-

$ sudo service nginx start

$ sudo netstat -eplant |grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          34868      2996/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      0          34869      2996/nginx: master  


$ curl -I localhost
HTTP/1.1 200 OK
Server: nginx/1.18.0

相关内容