Rails 应用程序在端口 3000 上运行:
$ bundle exec rails server -b 0.0.0.0
=> Booting Unicorn
=> Rails 3.2.21 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
(eval):1: warning: encountered \r in middle of line, treated as a mere space
listening on addr=0.0.0.0:3000 fd=14
worker=0 spawning...
master process ready
worker=0 spawned pid=5811
worker=0 ready
网站可在虚拟机上使用:
$ wget 127.0.0.1:3000
--2016-05-05 05:15:54-- http://127.0.0.1:3000/
Connecting to 127.0.0.1:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html'
[ <=> ] 42,036 --.-K/s in 0s
2016-05-05 05:15:55 (222 MB/s) - `index.html' saved [42036]
但从主机来看:
$ wget http://127.0.0.1:3000/
--2016-05-05 00:07:02-- http://127.0.0.1:3000/
Connecting to 127.0.0.1:3000... failed: Connection refused.
端口扫描主机:127.0.0.1:
Open TCP Port: 21 ftp
Open TCP Port: 22 ssh
Open TCP Port: 80 http
Open TCP Port: 88 kerberos
Open TCP Port: 111 sunrpc
Open TCP Port: 445 microsoft-ds
Open TCP Port: 548 afpovertcp
Open TCP Port: 631 ipp
Open TCP Port: 965
Open TCP Port: 975
Open TCP Port: 1015
Open TCP Port: 1019
Open TCP Port: 2049 nfsd
Open TCP Port: 2200 ici
Open TCP Port: 2222 rockwell-csp2
Open TCP Port: 3300
Open TCP Port: 5432 postgresql
Open TCP Port: 8080 http-alt
这是基本内容/private/etc/hosts
:
127.0.0.1 localhost
127.0.0.1 test.localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
192.168.33.102 vagrant # VAGRANT: c460068dd8a5a09607cfd3402843d82a (local) / 0668df93-b211-421f-86db-bb2ff8e57175
192.168.44.44 vdd.dev # VAGRANT: 07e9613958e0db441d6b9af1328fa214 (default) / 4d655cd6-bf5a-442a-8093-4ac431b7d890
nginx/error.log
据我所知,这只是确认拒绝连接并且 Unicorn 日志同样没有提供任何信息。
这是内容/etc/nginx/sites-available/my_application
:
upstream unicorn {
server unix:/home/vagrant/apps/ofn_america/shared/sock/unicorn.ofn_america.sock fail_timeout=1;
}
server {
listen 80;
server_name 127.0.0.1;
rewrite ^/(.*) http://127.0.0.1/$1 permanent;
}
server {
listen 80;
server_name 127.0.0.1;
root /home/vagrant/apps/ofn_america/current/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_pass http://unicorn;
}
location ~ ^/(assets)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
#add_header Last-Modified "";
#add_header ETag "";
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 60;
}
有什么建议么?
我不确定还有什么地方可以探索。
答案1
听起来你需要将流量从主机转发到客户机。我不太熟悉 Vagrant,但这看起来像是你可以这样做:
https://www.vagrantup.com/docs/networking/forwarded_ports.html