[英]OS X Vagrant host unable to connect to Apache/Passenger Server on Redirect
I am trying to configure a Yosemite Vagrant box to work with my Yosemite machine. 我正在尝试配置优胜美地游民箱以与我的优胜美地机器一起使用。 I have a Ruby 1.8.7/Rails 2 (you read correctly) application running on top of Passenger with the Apache module. 我有一个在Apache 乘客平台上运行的Ruby 1.8.7 / Rails 2 (您正确阅读)的应用程序。 I'm very new to both servers and Vagrant, and I'm struggling to share the Vagrant box's application on my host machine, even though I've verified the guest environment by connecting to the GUI (VirtualBox) and navigating to the dev site via Chrome. 我对服务器和Vagrant都非常陌生,即使我已经通过连接到GUI(VirtualBox)并导航到开发站点来验证了来宾环境,我仍在努力在主机上共享Vagrant box的应用通过Chrome。 I suspect it's something to do with the redirects in my apache config , and I'll demonstrate why. 我怀疑这与我的apache config中的重定向有关 ,我将演示原因。
Here's my apache config ( /etc/apache2/other/[my_custom].conf ). 这是我的apache配置( /etc/apache2/other/[my_custom].conf )。
Note the RedirectPermanent
lines, as well as the separate codebases that we are serving : 请注意RedirectPermanent
行以及我们提供的单独的代码库 :
LoadModule passenger_module /Users/vagrant/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /Users/vagrant/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/gems/passenger-4.0.59
PassengerDefaultRuby /Users/vagrant/.rbenv/versions/ree-1.8.7-2012.02/bin/ruby
</IfModule>
LogFormat "%h %p %l %u %t \"%r\" %>s %b"
<VirtualHost *:80>
ServerName [servername].dev
RedirectPermanent / "http://www.[servername].dev/"
</VirtualHost>
<VirtualHost *:80>
ServerName [subdomain1].[servername].dev
ServerAlias [subdomain2].[servername].dev
RailsEnv development
DocumentRoot /Users/vagrant/code/[codebase1]/public
<Directory /Users/vagrant/code/[codebase1]/public>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
RedirectPermanent /[subdomain1] "http://[subdomain1].[my_servername].dev"
RedirectPermanent /[subdomain2] "http://[subdomain2].[my_servername].dev"
Include /Users/vagrant/code/[codebase1]/config/php/httpd/passenger_routes.conf
</VirtualHost>
<VirtualHost *:80>
ServerName www.[servername].dev
RailsEnv development
DocumentRoot /Users/vagrant/code/[codebase2]/public
<Directory /Users/vagrant/code/[codebase2]/public>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
RedirectPermanent /[subdomain1] "http://[subdomain1].[my_servername].dev"
RedirectPermanent /[subdomain2] "http://[subdomain2].[my_servername].dev"
Include /Users/vagrant/code/[codebase2]/config/php/httpd/passenger_routes.conf
</VirtualHost>
/etc/hosts file on my Vagrant box: 我的Vagrant框上的/ etc / hosts文件:
127.0.0.1 localhost
255.255.255.255 broadcast
::1 localhost
127.0.0.1 www.[servername].com
127.0.0.1 [subdomain1].[servername].com
Vagrantfile : Vagrantfile :
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "jhcook/osx-yosemite-10.10"
config.vm.network "forwarded_port", guest: 80, host: 8080,
auto_correct: true
end
When I boot up apache in the Vagrant box and navigate to www.[servername].com
or [subdomain1 or 2].[servername].com
, the site comes up as expected. 当我在“ Vagrant”框中启动apache并导航到www.[servername].com
或[subdomain1 or 2].[servername].com
,站点将按预期启动。 However, when I go to the host machine and navigate to http://localhost:8080
, the request times out after hanging for about 2 min. 但是,当我转到主机并导航到http://localhost:8080
,挂起大约2分钟后,请求超时。
When I curl -i "http://localhost:8080"
on my host machine, I get 当我在主机上curl -i "http://localhost:8080"
时,我得到
HTTP/1.1 301 Moved Permanently Date: Wed, 07 Oct 2015 19:44:27 GMT Server: Apache/2.4.16 (Unix) Phusion_Passenger/4.0.59 PHP/5.5.27 Location: http://www.[servername].dev/ Content-Length: 227 Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://www.[servername].dev/">here</a>.</p> </body></html>
And when I curl -i "http://www.[servername].dev"
, the terminal hangs for about 2 minutes and finally returns curl: (7) Failed to connect to www.[servername].dev port 80: Operation timed out
. 当我curl -i "http://www.[servername].dev"
,终端挂起大约2分钟,最后返回curl: (7) Failed to connect to www.[servername].dev port 80: Operation timed out
。 However, when I navigate my VirtualBox GUI to www.[servername].dev, the page is served up fine. 但是,当我将VirtualBox GUI导航到www。[servername] .dev时,页面显示良好。
I checked the apache logs, and the requests to localhost:8080
on my host machine are not registering, so my suspicion is that there's something about the redirect and reserved ports that's preventing my host machine from accessing this app. 我检查了apache日志,并且对localhost:8080
上的localhost:8080
的请求未注册,因此我怀疑重定向和保留端口存在某些问题,这些问题阻止了主机访问此应用程序。
Quick list of other things I've tried (glad to explain further if needed): 我尝试过的其他操作的快速列表(如果需要,可以高兴地进一步解释):
private_network
: same general problems (curling get's a redirect, going to redirect URL hangs) Vagrantfile private_network
:相同的一般问题(卷曲获取重定向,将重定向URL挂起) private_network
: same problems, new IP 在有和没有Vagrantfile private_network
情况下,在apache配置(例如10.10.0.0)中分配设置的IP地址:同样的问题,新的IP auto_correct
尝试了Vagrantfile而不使用auto_correct
guest: 80, host: 80
with no success 尝试与guest: 80, host: 80
的端口转发失败 I'm trying to avoid using vagrant share
in any way, so that this box is a little more self-contained. 我试图避免以任何方式使用vagrant share
,以便使此框更加独立。
After hours of searching, poking, prodding, I realized that I never updated my host machine /etc/hosts file. 经过数小时的搜索,戳戳和探测,我意识到自己从未更新过主机 / etc / hosts文件。 Adding these two lines has allowed the port forwarding ( guest: 80, host: 8080
) to work: 添加这两行允许端口转发( guest: 80, host: 8080
)工作:
127.0.0.1 www.[servername].com
127.0.0.1 [subdomain1].[servername].com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.