0

複数のドメインを使用して、同じ VPS で複数の異なる Rails アプリをホストしようとしています。Ubuntu 10.10 で Apache 2.2.17 を使用しています。Apache の場合、複数の vhost ファイルがあるため、特定のサイトをコメント アウトしたり削除したりすることなく、簡単に有効化および無効化できます。また、mod_rewrite を使って、同じ rails app に行く複数のドメインが同じ URL に行くように見えるようにして、コンテンツが重複する限り検索エンジンにヒットしないようにしています。

DNS が適切に設定されていると思います。ドメインごとに、wwwサブドメインと、ブログなどのサイト固有のサブドメインがあります。私が見ている問題は、Apache がwwwサブドメインをすぐに照合し、その背後にある追加の URL を調べていないように見えることです。変更しても何も起こりServerAliasません。たとえば、私の設定を使用して、 と入力するdavidheartsrachel.comと、結婚式の Web サイトに適切にアクセスできます。ただし、を使用するwww.davidheartsrachel.comと、ソフトウェア開発ビジネスである別の Web サイトにアクセスできます。URL は書き換えられません。davidheartsrachel.comの代わりにそのままですafewguyscoding.com

私が適切に動作させることができた唯一の方法は、プライマリ vhost ファイルで mod_rewrite を使用して、結婚式のウェブサイトの vhost ファイルにリダイレクトすることです (プライマリ vhost ファイルにそれがあることがわかりますが、コメントアウトされていますこの質問の目的)。これは私には適切ではないようですか?別の IP を取得して、名前ベースの vhost の代わりに 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>

結婚式場の vhost ファイル

<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に行くのですか

4

2 に答える 2

0

サーバーでは、メインのhttpd.confファイルにプライマリサイトを定義していません。私はすべての仮想ホスティングを個別のアプリケーション固有のconfファイルで行います。

メインのhttpd.confにあるのは、次の行だけです。NameVirtualHost *:80

これがあなたがそれを試すことができる方法の要点です。私はあなたのメインサイトの構成からすべての結婚式のサイトの構成を引き出しました。davidstites.com、afewguyscoding.com、およびwww.davidstites.comがすべてwww.afewguyscoding.comにリダイレクトされるように設定しました。他のドメイン(milehigh et al)は影響を受けません。どこに行きたいのかわかりません。

すべての結婚式関連ドメインはwww.davidheartsrachel.comにリダイレクトされます。

メインサイトの構成が混乱している可能性があることに気づきました。ディレクトリのアクセス許可を設定する最後の方で、DocumentRootである/ var / www/wpressの代わりに/var/ www / afewguyscoding / current/publicディレクトリを使用していました。私がそこで行った修正は、その要点の最初の文書の74行目にあります。

于 2011-06-28T19:48:21.737 に答える
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
于 2011-06-29T18:02:34.147 に答える