Centos 7では、複数の仮想ホストが連携しない

Centos 7では、複数の仮想ホストが連携しない

私のサーバー情報は

Server version: Apache/2.4.6 (CentOS)
Server built:   Nov 19 2015 21:43:13

同じサーバーでホストされているbiz.example.comとpin.example.comという2つの異なるサイトの仮想ホスティングを構成しようとしています。 「var/www/html/」の下には、「biz」と「pin」という2つの異なるフォルダがあります。これには、上記の2つのウェブサイトの重要なプロジェクトファイルが含まれています。以下のように設定しようとしています。

/etc/hosts 以下の設定で

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

xxx.xxx.xxx.xxx biz.example.com
xxx.xxx.xxx.xxx pin.example.com

xxx.xxx.xxx.xxxをサーバーのIPアドレスに置き換えます。

/etc/httpd/conf/httpd.confから

IncludeOptional sites-enabled/*.conf

これで、/etc/httpd/sites-available の下に biz.conf と pin.conf ファイルがあります。また、次のコマンドを使用して、サイトアクティベーションフォルダを指す2つのbiz.confファイルとpin.confファイルを含む/ etc / httpdの下にサイトアクティベーションフォルダを有効にしました。

ln -s /etc/httpd/sites-available/biz.conf /etc/httpd/sites-enabled/biz.conf

ln -s /etc/httpd/sites-available/pin.conf /etc/httpd/sites-enabled/pin.conf

biz.confには次の内容があります

<VirtualHost *:80>
ServerName http://biz.example.com/
ServerAlias http://biz.example.com/
DocumentRoot "/var/www/html/biz"
<directory "/var/www/html/biz">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Allow from 127.0.0.1
</directory>
</VirtualHost>

pin.conf ファイルの構成は次のように言及されます。

<VirtualHost *:80>
ServerName http://pin.example.com/
ServerAlias http://pin.example.com/
DocumentRoot "/var/www/html/pin"
<directory "/var/www/html/pin">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Allow from 127.0.0.1
</directory>
</VirtualHost>

この設定からアクセスしようとするとhttp://biz.example.com/、正しいウェブサイト(ビジネスウェブサイト)が読み込まれています。しかし、私がアクセスしようとするとhttp://pin.example.com/をクリックして、固定ウェブサイトの代わりにビジネスウェブサイトを読み込みます。複数の構成を一緒に使用することはできません。

また、biz.confとpin.confのダミー構成を単一のファイルbiz.confにマージしようとしましたが、うまくいきませんでした。

ベストアンサー1

答え:

1) ServerName と ServerAlias の末尾のスラッシュを削除する必要があります。

2) ここで ServerAlias を削除でき、ServerName と ServerAlias の両方が同じです。

おすすめ記事