【发布时间】:2016-08-16 11:40:35
【问题描述】:
如何让我的主机 (Windows 10) 显示托管在我的 Vagrant (Ubuntu 14.04) 上的测试站点。当我尝试在 Ubuntu 上执行 curl localhost.ng:81 时,我可以看到它显示 nginx 默认页面,但是当我尝试访问 localhost.ng:81 或 localhost.ng:8100 在我的主机 (Windows) 上显示 此网页不可用。以下是我的配置
Windows etc/hosts 文件:
192.168.0.25 localhost.ng
Vagrant 文件网络配置:
config.vm.network "forwarded_port", guest: 81, host: 8100
config.vm.network "private_network", ip: "192.168.0.25"
config.vm.network "public_network"
Nginx 虚拟主机配置:
server {
listen 81 default_server;
listen [::]:81 default_server ipv6only=on;
root /development/nginx/sites;
index index.php index.html index.htm;
server_name localhost.ng;
location / {
try_files $uri $uri/ =404;
autoindex on;
}
#error_page 404 /404.html;
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
#root /development/nginx/sites;
#}
location ~ \.php$ {
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
/etc/hosts 配置:
127.0.0.1 localhost
127.0.0.2 localhost.ng
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.1.1 developer developer
日志:
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
default: Adapter 3: bridged
==> default: Forwarding ports...
default: 81 (guest) => 8100 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
/development/nginx/sites 下的文件设置为 777 模式并归 www:data 所有,因为这只是为了测试。任何帮助将不胜感激,谢谢
【问题讨论】:
-
可以肯定的是,您不应该将
private_networkIP 地址设置为与您的主机相同的值。您最终会得到两台具有相同 IP 的机器。这是否会阻止端口转发很难说,在这种情况下它可能会随机运行。 -
@techraf 谢谢,我刚刚发现我在虚拟机上使用的 IP 不在我的主机的 IP 范围内。
标签: ubuntu nginx configuration server vagrant