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

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

问题描述

我正在从 Dreamhost 切换到 Rackspace Cloud 托管,因为前者处理 Rails 应用程序的能力有待改进.我已经设置了一个 CentOS 服务器,我已经部署了我的 rails 应用程序,域解析,一切都很好.现在我想设置它,所以如果我直接转到 IP 地址,我将获得普通的 apache 目录而不是 rails 应用程序.我以为虚拟主机可以管理这个,但现在他们都去 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?

推荐答案

Apache 将第一个虚拟主机作为所提供 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.

请注意,如果您将虚拟主机记录拆分为多个文件(即,sites-available/sites-enabled 文件夹).Apache 按字母顺序加载它们,通常在基于 debian 的系统上,您会看到 000-default 或类似文件.这个在开始时使用数字来确保它总是第一个加载并承担主要虚拟主机的角色

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天全站免登陆