異なるドメインで使用するアプリディレクトリをApacheに知らせるにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/1025587

質問

CodeIgniterでサイトを作成しようとしています。このサーバーから複数のドメインを提供し、www.example1.comのHTTPリクエストをwww.example2.comのHTTPリクエストから分離し、正しいアプリケーションフォルダーにリダイレクトすることを試みています。

これが私のディレクトリ構造であるとします:

  • システム
    • アプリケーション
      • example1
      • example2

このリクエスト

www.example1.com/gallery/

その後、exmaple1フォルダーにリダイレクトされます。

これを行うためのコード例はありますか?明らかに、ReWriteモジュールを使用する必要があります...

Apacheのドキュメントを調べましたが、どこにも行きませんでした。これについてさらに情報が必要な場合はお知らせください。

役に立ちましたか?

解決

VirtualHost(およびAlias、Rewrite)を使用することが主な答えですが、同じセットアップを使用して他のホストを追加/削除すると思われる場合は、 mod_macro モジュール。これは、Apacheの設定を簡素化し、コピー/貼り付けエラーを回避するのに役立つサードパーティモジュールです。

レイアウトの簡単な例では、次を定義します:

<Macro vh80 name>
 <VirtualHost *:80>
   DocumentRoot /system/application/$name
   ServerName www.$name.com
   CustomLog /system/application/$name/logs/access.log virtcommon
   ErrorLog /system/application/$name/logs/error.log
 </VirtualHost>
</Macro>

そして、サイトを有効にするときは、次のディレクティブを使用します:

  

vh80 example1を使用

www.example1.comをセットアップして、構成されたディレクトリをルートおよび構成されたロギングディレクトリとして使用します。

他のヒント

必要なものは VirtualHost と呼ばれ、www.example1を作成します。 .comとwww.exaplme2.comは、それぞれファイルシステム内の異なるフォルダーを指します。

メインコンテンツを提供するためのURIに別のパスを追加する場合は、さまざまな選択肢があります:

  1. フォルダを物理的に作成し、それ以上の変更は行いません

  2. フォルダーへのリンク(メインの仮想ホストルートフォルダーを指すギャラリーという名前)を物理的に作成し、 VirtualHostのFollowSymLinks オプション

  3. VirtualHostでエイリアスディレクティブを使用する

    Alias /gallery /
    
  4. mod_rewriteを使用

    RewriteRule /gallery/(.*) /$1 [QSA]
    

最も単純な(CodeIgniterが許可する)オプション1または2になります。

VirtualHostドキュメントのスニペット:

Running several name-based web sites on a single IP address.

Your server has a single IP address, and multiple aliases (CNAMES) 
point to this machine in DNS. You want to run a web server for 
www.example.com and www.example.org on this machine.

Note

Creating virtual host configurations on your Apache server does 
not magically cause DNS entries to be created for those host 
names. You must have the names in DNS, resolving to your IP 
address, or nobody else will be able to see your web site. 
You can put entries in your hosts file for local testing, 
but that will work only from the machine with those hosts 
entries.

Server configuration

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

The asterisks match all addresses, so the main server serves no requests. 
Due to the fact that www.example.com is first in the configuration file, 
it has the highest priority and can be seen as the default or primary 
server. That means that if a request is received that does not match 
one of the specified ServerName directives, it will be served by this
first VirtualHost.

これは実際には2つの質問です。

  1. www.example1.comとwww.example2.comを異なるものにする方法これに対する答えは、 VirtualHost ディレクティブです。

  2. / galleryがexample1を指すようにする方法は?これはAliasディレクティブを使用して行われます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top