nginx on vagrant:请求未到达虚拟主机/服务器块

nginx on vagrant:请求未到达虚拟主机/服务器块,nginx,vagrant,virtualhost,reverse-proxy,portforwarding,Nginx,Vagrant,Virtualhost,Reverse Proxy,Portforwarding,我目前正在一个流浪设置上运行一个nginx实例。我正试图通过设置虚拟主机/服务器块,让我的nginx运行两个不同的url dev.v1.example.com和dev.v2.example.com vagrant端口转发工作正常,我可以从主机访问nginx config.vm.network "forwarded_port", guest: 80, host: 8980 当然,这意味着我要在主机上的浏览器上访问它们,我必须输入dev.v1.example.com:8980 来宾上的My ngi

我目前正在一个流浪设置上运行一个nginx实例。我正试图通过设置虚拟主机/服务器块,让我的nginx运行两个不同的url dev.v1.example.com和dev.v2.example.com

vagrant端口转发工作正常,我可以从主机访问nginx

config.vm.network "forwarded_port", guest: 80, host: 8980
当然,这意味着我要在主机上的浏览器上访问它们,我必须输入dev.v1.example.com:8980

来宾上的My nginx.conf是您的标准默认nginx.conf

    # For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

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

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

        location / {
        }

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

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

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}
我在conf.d/vhost.conf上有以下文件

server {
    listen 80;
    server_name dev.v1.example.com;
    root   /vagrant/dev_v1;
}

server {
    listen 80;
    server_name dev.v2.example.com;
    root   /vagrant/dev_v2;
}
每当我从主机请求dev.v1.example.com:8980或dev.v2.example.com:8980时,我从不点击服务器块并始终获得默认的nginx起始页,这是默认服务器块指向的。它永远无法在各自的根文件夹中显示每个特定服务器名称的内容,但我认为服务器块会被给定配置方式的请求击中

我也尝试过将vhost.conf中的侦听端口更改为8980,但将服务器名称更改为附加8980端口并不起作用,因为8980端口始终不变,我可以在请求中看到“Host”头是dev.v1.example.com:8980,这也是在vagrant guest的nginx日志中出现的

有什么想法吗


提前感谢

在主机上创建一个反向代理,其中包含两个上游代理:

上游dev1\u\u上游{
服务器192.168.33.2:80;
保持64;
}
上游dev2_uuu上游{
服务器192.168.33.3:80;
保持64;
}