Configuring virtual hosts on apache2

北城余情 提交于 2020-01-13 07:01:11

问题


I'm switching from Dreamhost to Rackspace Cloud hosting, since the formers ability to handle a rails app left something to be desired. I've got a CentOS server all set up and I've got my rails app deployed and the domains resolve and everything is great. Now I want to set it up so if I go directly to the IP address I'll get the the normal apache directory instead of the rails app. I thought the virtual host could manage this, but now both of them go to rails page or the apache page, as the case may be

<VirtualHost *:80>
  ServerName 123.456.789.101
  DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
  ServerName mywebsite.com
  ServerAlias www.mywebsite.com
  DocumentRoot /rails/myapp/current/public
  <Directory /rails/myapp/current/public>
    AllowOverride all
    Options -MultiViews
  </Directory>
</VirtualHost>

I'm not quite sure how to proceed, or if this is just impossible to begin with. Thoughts?


回答1:


Apache takes the very first virtualhost to be it's primary host for the provided IP, (or all IP's in the case of *). Therefore you should be able to just setup your main virtual host record, make sure its the first vhost record that get's loaded and it will load that virtualhost whenever an unbound IP or unbound address is encountered. Then specify a second virtual host with the specific domains/subdomains you want to point to your rails app.

Please note that if you split your virtual host records across multiple files (i.e. sites-available/sites-enabled folders). Apache loads them in alphabetical order, often on debian based systems you will see the 000-default or similer file. This one uses numbers at the start to ensure its always the first one loaded and takes on the role of primary vhost



来源:https://stackoverflow.com/questions/9484676/configuring-virtual-hosts-on-apache2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!