基于 VirtualBox 的 Vagrant VM 中的 NGINX 不响应除 localhost 之外的任何人

问题描述 投票:0回答:1

非常短的问题,

[vagrant@localhost ~]$ curl http://0.0.0.0

我可以看到 NGINX 和 Redhat 的整个 HTML 页面,但我无法使用 VirtualBox 的主机和访客网络的公共 IP 或桥接 IP (10.XX.XX....) 连接到该主机服务器。他们无限期地挂断了(是的,没有连接错误,只是无限加载)

[vagrant@localhost ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources: 
  services: cockpit dhcpv6-client http ssh
  ports: 80/tcp 443/tcp
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

来自 nginx.conf:

server {
    listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

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

感谢所有帮助。系统本身是CentOS Stream 9: enter image description here

nginx vagrant virtualbox
1个回答
0
投票

问题与 VirtualBox + Vagrant 有关,因此添加了各自的标签。我只需在 Vagrantfile 中添加/取消注释这一行

config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

然后,瞧。我现在可以从

127.0.0.1:8080
访问 nginx 服务器。

因此,首先要执行以下步骤:

  1. 检查 server_name 是否设置为特定网站(如
    example.com
    ),或设置为任何内容
    _
    ,而不是特定 ip(如
    192.XXX
    )。
  2. 检查端口是否在
    firewalld
    中暴露,如果使用 CentOS,请对基于 Debian 的发行版进行研究。应该是一样的。
  3. 检查 Vagrantfile 或 Dockerfile 是否暴露了 80 端口。就是这样。
© www.soinside.com 2019 - 2024. All rights reserved.