我正在尝试使用多个域在同一个VPS上托管多个不同的rails应用。我在Ubuntu 10.10上使用Apache 2.2.17。对于Apache,我有多个vhost文件,这样我就可以轻松启用和禁用特定站点,而无需将其注释掉或删除它们。另外,我也使用mod_rewrite,以便转到同一个rails应用程序的多个域看起来转到相同的URL,所以就重复内容而言,我不会使用搜索引擎。
我相信我的DNS设置正确。对于每个域,我有一个www
子域以及一些特定于站点的子域,例如博客等。我看到的问题是Apache似乎与www
子域匹配立即而不检查它背后的额外URL。改变ServerAlias
什么都不做。例如,使用我的设置,如果我输入davidheartsrachel.com
,我就会正确到达我的婚礼网站。但是,如果我使用www.davidheartsrachel.com
,我会访问我的其他网站,即我的软件开发业务。 URL不会被重写;它保持为davidheartsrachel.com
而不是afewguyscoding.com
。
我能够正常使用它的唯一方法是在主vhost文件中使用mod_rewrite重定向到婚礼网站vhost文件(你可以看到我在主vhost文件中有这个,但它是为了这个问题的目的而注释掉了)。这对我来说似乎不合适?我应该获得另一个IP并执行IP vhost而不是基于名称的虚拟主机吗?
当我执行apachectl -S
时,我得到以下内容:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
port 80 namevhost afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
port 80 namevhost blog.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:69)
port 80 namevhost lbbs.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:84)
port 80 namevhost davidheartsrachel.com (/etc/apache2/sites-enabled/davidheartsrachel.com:1)
port 80 namevhost dhr.afewguyscoding.com (/etc/apache2/sites-enabled/davidheartsrachel_staging:1)
Syntax OK
我注意到afewguyscoding.com
是默认网站 - 但是,是否必须进行完整的字符串匹配才能确定正确的网站?
主站点的vhost文件
<VirtualHost *:80>
ServerAdmin david.stites@afewguyscoding.com
ServerName afewguyscoding.com
ServerAlias davidstites.com, 5280software.com, milehigh-software.com, milehighsoftware.org
ServerAlias www.5280software.com, www.milehigh-software.com, www.milehighsoftware.org, www.davidstites.com, www.afewguyscoding.com
# this tells rails that it will run in production mode
# this is for rails < 3.x
RailsEnv production
DocumentRoot /var/www/afewguyscoding/current/public
DirectoryIndex index.html
# custom log file locations
# possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel alert
ErrorLog /var/www/afewguyscoding/current/log/error.log
CustomLog /var/www/afewguyscoding/current/log/access.log combined
# allows compression of text based mime.types
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
FileETag None
RewriteEngine On
# check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
RewriteCond %{REQUEST_URI} !^/ws/
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html
#RewriteCond %{HTTP_HOST} ^www.davidheartsrachel.com$
#RewriteRule ^(.*)$ http://davidheartsrachel.com$1 [L]
RewriteCond %{HTTP_HOST} ^www.davidstites.com$
RewriteRule ^(.*)$ http://www.afewguyscoding.com$1 [R=301,L]
<Directory /var/www/afewguyscoding/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# In case I ever need CGI
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#<Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
#</Directory>
# how we can restrict access to documents from the local subnet
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0 ::1/128
<Location /blog>
PassengerEnabled off
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info@afewguyscoding.com
ServerName blog.afewguyscoding.com
DocumentRoot /var/www/wpress
DirectoryIndex index.php
<Directory /var/www/afewguyscoding/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
婚礼网站的虚拟文件
<VirtualHost *:80>
ServerAdmin info@davidheartsrachel.com
ServerName davidheartsrachel.com
ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com
ServerAlias www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net
# this tells rails that it will run in production mode
# this is for rails < 3.x
RailsEnv production
# this is for rails >= 3.x
RackEnv production
DocumentRoot /var/www/davidheartsrachel/current/public
DirectoryIndex index.html
# Custom log file locations
# Possible values include: debug, info, notice, warn, error, crit, alert and emerg,
LogLevel alert
ErrorLog /var/www/davidheartsrachel/current/log/error.log
CustomLog /var/www/davidheartsrachel/current/log/access.log combined
# Allows compression of text based mime types
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
FileETag None
RewriteEngine On
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
RewriteCond %{HTTP_HOST} ^www.rachelanddavidwedding.com$
RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.rachelanddavidstites.com$
RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]
# Static cache
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteCond /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html -f
RewriteRule ^(.*)$ /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html [L]
<Directory /var/www/davidheartsrachel/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
如果您能够想到任何可能有用的信息,请让我发布。
修改
让我试着澄清一下。在最重要的形式,我的问题是:为什么去davidheartsrachel.com带你到www.afewguyscoding.com和davidheartsrachel.com根据我的配置带你到davidheartsrachel.com
答案 0 :(得分:0)
在我的服务器上,我没有在主httpd.conf文件中定义主站点。我在单独的应用程序特定配置文件中执行所有虚拟主机。
我在主httpd.conf中唯一拥有的是NameVirtualHost *:80
行
Here's a gist你可以尝试一种方式。我从主站点配置中删除了所有婚礼站点配置。我将它设置为davidstites.com,afewguyscoding.com和www.davidstites.com都重定向到www.afewguyscoding.com。其他领域(milehigh等)不受影响。我不确定你想要去哪里。
所有与婚礼相关的域名都会重定向到www.davidheartsrachel.com。
我确实注意到我认为你的主站点配置可能搞得一团糟。在设置目录权限的最后,您使用/ var / www / afewguyscoding / current / public目录而不是DocumentRoot的/ var / www / wpress。我在那里进行的修正是在第一份文件的第74行。
答案 1 :(得分:0)
答案是我错误地将ServerAlias下的条目与逗号分开:
ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com, www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net
它应该是一个空间:
ServerAlias rachelanddavid.net rachelanddavidstites.com rachelanddavidwedding.com www.davidheartsrachel.com www.rachelanddavidstites.com www.rachelanddavidwedding.com www.rachelanddavid.net