使用Vagrant虚拟机和Nginx建立测试环境

时间:2017-10-16 19:16:01

标签: linux ssl nginx vagrant webserver

我正在尝试在centos / 6虚拟机上使用Vagrant设置本地Web测试环境

在我设置的流浪者配置中:config.vm.network "forwarded_port", guest: 80, host: 8080

如果我输入hostname -I,我会在流浪盒内部给出结果 10.0.2.15

In the vagrant box, nginx is already set and I do have a SSL certification and HTTPS connection set up:
server {
    listen       443;
    server_name 127.0.0.1:8000;
    ...(other configurations including ssl_certificate, 
    ssl_certificate_key,protocols and cipher)
    ...(other values that I think its not relevant)
    location / {
            if ($http_host != 127.0.0.1:8000) {
                return 444;
            }
    proxy_pass http://127.0.0.1:8000;
}

然后我有:

server {
    listen 80 default;
    server_name ~^;
    return 302 https://127.0.0.1:8000$request_uri;
}

在我的流浪盒中,如果我使用curl获取内容为127.0.0.1:8000:curl 127.0.0.1:8000,我就能成功获得预期内容

在我的主机操作系统中,当我使用chrome请求访问127.0.0.1时,它只是说The connection was reset.,错误异常代码为ERR_CONNECTION_RESET

我最好的猜测是,这必须处理我的SSL配置?

1 个答案:

答案 0 :(得分:0)

不确定这是否有帮助,我运行vagrant并使用Virtualbox作为我的虚拟机管理程序。您需要检查流浪盒对NAT的影响。在我的,开箱即用它是192.169.33.10,这将到我的开发箱。假设端口转发设置正确且没有防火墙。

192.168.33.10:8080做了什么?