Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 无法通过Google云VM的外部IP访问nginx容器_Google Cloud Platform - Fatal编程技术网

Google cloud platform 无法通过Google云VM的外部IP访问nginx容器

Google cloud platform 无法通过Google云VM的外部IP访问nginx容器,google-cloud-platform,Google Cloud Platform,我有一个谷歌云虚拟机,在端口8080上运行nginx docker容器。当我使用curl时,可以从机器内部访问nginx页面http://localhost:8080。但是,当我打开机器的外部IP(使用端口8080)时,我得到了chrome中拒绝的错误连接。我在创建VM时启用了http/https防火墙选项 下面是我使用的docker run命令和localhost上的curl检查: aayush_pathak15@instance-1:~/devops-environment$ sudo do

我有一个谷歌云虚拟机,在端口8080上运行nginx docker容器。当我使用
curl时,可以从机器内部访问nginx页面http://localhost:8080
。但是,当我打开机器的外部IP(使用端口8080)时,我得到了chrome中拒绝的错误连接。我在创建VM时启用了http/https防火墙选项

下面是我使用的docker run命令和localhost上的curl检查:

aayush_pathak15@instance-1:~/devops-environment$ sudo docker run -d -p 8080:80 nginx
f398231940eeb7194e0b4deb50936d7581cf32a451583e162cac40e829f9ebff
aayush_pathak15@instance-1:~/devops-environment$ curl http://localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
aayush_pathak15@instance-1:~/devops-environment$ 
我尝试添加另一个防火墙规则以允许所有端口(请忽略写有“jenkins”的无关命名)

下面是我的机器详细信息


这可能与“IP转发”关闭有关吗?(参见上图)

根据docker run语句中的
-p 8080:80
参数,docker run语句告诉它将主机上的端口8080发布到容器上的端口80,因此在这种情况下,您可以通过访问端口8080上节点的外部IP来访问外部端口8080<代码>34.68.171.6:8080

根据docker run语句中的
-p8080:80
参数告诉它将主机上的端口8080发布到容器上的端口80,因此在这种情况下,您可以通过访问端口8080上节点的外部IP从外部访问它<代码>34.68.171.6:8080

我使用

sudo docker run -d -p [Internal IP]:8080:80 nginx
我可以访问http://[外部IP]:8080上的nginx页面


还有必要添加问题中提到的防火墙规则。

我使用

sudo docker run -d -p [Internal IP]:8080:80 nginx
我可以访问http://[外部IP]:8080上的nginx页面


还有必要添加问题中提到的防火墙规则。

我们可以看看您是如何部署nginx容器的吗?你使用了什么工具,节点上的命令行,谷歌云控制台?您使用它运行了哪些参数?我只是简单地执行了“docker run-d-p8080:80nginx”,容器就成功地启动并运行了。Curling localhost:8080为我提供了正确的nginx默认页面。但是它没有使用我浏览器上vm的外部IP打开,而是在
localhost
0.0.0
上监听?显示问题中的配置文件。@JohnHanley Nginx正在我的虚拟机上侦听localhost。我在问题中包括了一个curl输出以及所有打开端口的列表(以显示docker肯定正在使用端口8080)。如果这回答了您的问题,请告诉我。如果您将Nginx配置为在
localhost
上侦听,则无法从Internet访问该服务。将侦听地址更改为
0.0.0.0
<代码>本地主机只能通过环回设备在操作系统内部访问。将
localhost
视为操作系统内部的专用网络。我们可以看看您是如何部署nginx容器的吗?你使用了什么工具,节点上的命令行,谷歌云控制台?您使用它运行了哪些参数?我只是简单地执行了“docker run-d-p8080:80nginx”,容器就成功地启动并运行了。Curling localhost:8080为我提供了正确的nginx默认页面。但是它没有使用我浏览器上vm的外部IP打开,而是在
localhost
0.0.0
上监听?显示问题中的配置文件。@JohnHanley Nginx正在我的虚拟机上侦听localhost。我在问题中包括了一个curl输出以及所有打开端口的列表(以显示docker肯定正在使用端口8080)。如果这回答了您的问题,请告诉我。如果您将Nginx配置为在
localhost
上侦听,则无法从Internet访问该服务。将侦听地址更改为
0.0.0.0
<代码>本地主机只能通过环回设备在操作系统内部访问。将
localhost
视为操作系统内部的专用网络。道歉。我也在使用8080端口和外部IP。我编辑了这个问题以澄清这一点。抱歉。我也在使用8080端口和外部IP。我对问题进行了编辑,以澄清这一点。