配置上apache2的虚拟主机 [英] Configuring virtual hosts on apache2

查看:152
本文介绍了配置上apache2的虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从切换到Dreamhost的Rackspace的云托管,因为前人处理一个Rails应用程序的能力留给不满意。我有一个CentOS服务器的所有设置和我有我的Rails应用程序部署和领域的决心和一切都很好。现在我想将其设置,所以如果我直接去了IP地址,我会得到正常的Apache目录,而不是Rails应用程序。我以为虚拟主机可以管理这个,但现在他们都去导轨页或Apache页面,具体情况而定。

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?

推荐答案

阿帕奇采用的第一虚拟主机是它是提供的IP主要主机(或所有IP的在*的情况下)。因此,你应该可以只设置您的主要虚拟主机记录,确保其是那些获得的加载,它会载入每当遇到一个未绑定的IP或绑定地址的虚拟主机的第一个虚拟主机记录。然后你要指向您的Rails应用程序的特定的域/子域指定第二个虚拟主机。

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.

请注意,如果您拆分到多个文件,虚拟主机记录(即网站的可用/站点启用文件夹)。阿帕奇加载它们按字母顺序排列,经常在基于Debian的系统,你会看到000默认或similer文件。在开始这一个使用号码以确保其总是第一个加载并呈现虚拟主机的主要的作用

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

这篇关于配置上apache2的虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆