简体   繁体   English

OS X Vagrant主机无法通过重定向连接到Apache / Passenger Server

[英]OS X Vagrant host unable to connect to Apache/Passenger Server on Redirect

Unsuccessful redirects from Vagrant guest to host 从Vagrant来宾到主机的重定向失败

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

Things I've tried: 我尝试过的事情:

  1. 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分钟后,请求超时。

  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时,页面显示良好。

  1. 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的请求未注册,因此我怀疑重定向和保留端口存在某些问题,这些问题阻止了主机访问此应用程序。

  2. Quick list of other things I've tried (glad to explain further if needed): 我尝试过的其他操作的快速列表(如果需要,可以高兴地进一步解释):

    • Successfully verified that a different app can be accessed via host machine (used port 3000 for a Rails API, 8988 for Solr admin panel . . . ) 成功验证可以通过主机访问其他应用程序(Rails API使用端口3000,Solr管理面板使用8988)。
    • Vagrantfile private_network : same general problems (curling get's a redirect, going to redirect URL hangs) Vagrantfile private_network :相同的一般问题(卷曲获取重定向,将重定向URL挂起)
    • Assigning new port in my apache config (eg 9000): same problems, new port 在我的apache配置中分配新端口(例如9000):同样的问题,新的端口
    • Assigning set IP address in apache config (eg 10.10.0.0) with and without Vagrantfile private_network : same problems, new IP 在有和没有Vagrantfile private_network情况下,在apache配置(例如10.10.0.0)中分配设置的IP地址:同样的问题,新的IP
    • Tried the Vagrantfile without auto_correct 尝试了Vagrantfile而不使用auto_correct
    • Tried the port forwarding with guest: 80, host: 80 with no success 尝试与guest: 80, host: 80的端口转发失败
  3. I'm trying to avoid using vagrant share in any way, so that this box is a little more self-contained. 我试图避免以任何方式使用vagrant share ,以便使此框更加独立。

Does anyone have experience working with redirects in Apache inside a Vagrantbox? 有没有人有在Vagrantbox中使用Apache进行重定向的经验?

How can I get my guest to forward the redirect to the host as well? 我如何让我的客人也将重定向转发到主机?

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.

相关问题 在Vagrant上连接到主机MySQL服务器 - Connect to Host MySQL Server on Vagrant 在主机 mac os x 浏览器中无法访问在流浪环境中运行的 rails 2.3 服务器 - rails 2.3 server running inside vagrant environment not accessible in host machine mac os x browsers 在OS X 10.6 Snow Leopard上安装Passenger-Apache2 - Installing Passenger-Apache2 on OS X 10.6 Snow Leopard OS X:使用Apache和Passenger进行RoR的开发和生产部署 - OS X: Development & Production Deployment for RoR with Apache and Passenger 如何使用Apache和Passenger在Max OS X上部署Rails应用 - How to deploy Rails app on Max OS X, with Apache and Passenger 无法为Apache启用乘客模块 - Unable to enable passenger module for apache 具有RVM的本地OS X开发人员计算机上的passenger-install-apache2-module问我要安装其他红宝石吗? - passenger-install-apache2-module on local OS X dev machine with RVM is asking me to install a different ruby? 带有资产管道的Rails 4,Passenger和Apache虚拟主机 - Rails 4, Passenger, and Apache virtual host with asset pipeline BitNami Apache Passenger启动服务器 - BitNami Apache Passenger start Server Rails / Passenger / Apache:服务器迁移后,简单的一次性URL重定向即可捕获陈旧的DNS - Rails/Passenger/Apache: Simple one-off URL redirect to catch stale DNS after server move
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM