在虚拟机上部署一个nginx容器,容器启动了,虚拟机访问不了nginx服务

图片说明
图片说明
图片说明

把niginx的配置文件发出来。通常容器具有不同的Docker网络。所以如果在 proxy_pass 中设置 upstream 时,需要避免使用错误的 ip 地址。

更新说明:

确认本机的80端口没有被占用,通过以下命令来检查 netstat -ltn

执行以下命令

docker run --name mynginx1 -p 80:80 -d nginx

查看运行状态,结果应该是这样的

# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
55842f880365        nginx               "nginx -g 'daemon ..."   16 seconds ago      Up 15 seconds       0.0.0.0:80->80/tcp   mynginx1

注意这里的COMMAND和你的不一样哦

测试

# curl localhost:80
<!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>