同じサーバー上の複数のドメインに対してhttpdを構成する

同じサーバー上の複数のドメインに対してhttpdを構成する

CentOS 7 Webサーバーはmydomain.comというパブリックドメインをホストしています。同じサーバーには、承認/認証された個人ユーザーのみが使用できる2つのアプリケーションをホストする別々のVPNがあります。 httpdはtomcatの前にリバースプロキシリレーションを設定します。以下の設定では、すべてが完全に実行されます。

サーバーがパブリックに別のドメイン、domain2.com、domain3.com、domain4.comをホストできるように、以下の設定をどのように変更しますか? Tomcatインスタンスは3つです。ポート8011はパブリックサイトのTomcatインスタンスを指し、ポート8009と8010はプライベートVPNアプリケーションのTomcatインスタンスを指します。

/etc/httpd/conf.d/hostname.conf以下はインクルードファイルで示されるコードです/etc/httpd/conf/httpd.conf

<VirtualHost *:443>
    ServerName www.bogusdomainforvpn.com
    ServerAlias bogusdomainforvpn.com
    ErrorLog /var/log/httpd/bogusdomainforvpn_com_error.log
    CustomLog /var/log/httpd/bogusdomainforvpn_com_requests.log combined
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ProxyPass / ajp://ip.address.of.server:8009/
    ProxyPassReverse / ajp://ip.address.of.server:8009/
</VirtualHost>

Listen 444

<VirtualHost *:444>
    ServerName www.bogusdomainforvpn.com
    ServerAlias bogusdomainforvpn.com
    ErrorLog /var/log/httpd/bogusdomainforvpn_com_error.log
    CustomLog /var/log/httpd/bogusdomainforvpn_com_requests.log combined
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ProxyPass / ajp://ip.address.of.server:8010/
    ProxyPassReverse / ajp://ip.address.of.server:8010/
</VirtualHost>

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    ErrorLog /var/log/httpd/mydomain_com_error.log
    CustomLog /var/log/httpd/mydomain_com_requests.log combined
    ProxyPass / ajp://ip.address.of.server:8011/
    ProxyPassReverse / ajp://ip.address.of.server:8011/
</VirtualHost>

ベストアンサー1

VirtualHostSSL / TLSを使用していない場合は、各Webサイトに追加してください。

<VirtualHost www.domain2.com:80>
    ServerName www.domain2.com
    ErrorLog /var/log/httpd/domain2_com_error.log
    CustomLog /var/log/httpd/domain2_com_requests.log combined
    # You probably want either the next line:
    DocumentRoot /var/www/domain2.com
    # or the next two lines: (but not all three)
    # ProxyPass / ajp://ip.address.of.server:8012/
    # ProxyPassReverse / ajp://ip.address.of.server:8012/
</VirtualHost>

# You only need this block if DocumentRoot is used above:
<Directory /var/www/domain2.com>
    # this enables full control using .htaccess - change for your setup
    AllowOverride All
</Directory>

<Directory>CentOSはデフォルトのルートディレクトリ以外のすべてのエントリへのアクセスを制限するため、このエントリが必要になる場合があります/var/www/html。ニーズに合わせて編集してください。

このセクションとの唯一の違いは、エージェントエントリをファイルが保存されているディレクトリを指すエントリにVirtualHost置き換えることです。DocumentRoot私はあなたがローカルのApacheサーバーからページを提供していると仮定します。元のサイトでTomcatを使用している場合www.mydomain.com(適切に編集された場合)、行を保持してProxyPass項目やセクションをProxyPassReverse追加しないでください。DocumentRoot<Directory>

SSL / TLSサイトでは同様の設定が必要ですが、ポートを443に変更して証明書関連のエントリを変更します。

<VirtualHost www.domain2.com:443>
    ServerName www.domain2.com
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/domain2.crt
    SSLCertificateKeyFile /etc/pki/tls/private/domain2.key
    ErrorLog /var/log/httpd/domain2_com_error.log
    CustomLog /var/log/httpd/domain2_com_requests.log combined
    DocumentRoot /var/www/domain2.com
</VirtualHost>

SSL/TLS を使用するこの仮想名前付きホスティングは、次に依存します。サーバー名の表示。以前のバージョンはSNIをサポートしていなかったため、この機能を使用するにはVistaでInternet Explorer 7以降が必要です。 Linuxでは、過去10年前半の非常に古いブラウザを使用しない限り、かなり安全です。

唯一の問題は、bogusdomainforvpn.comポート443がすでに使用中であることです。これはSSL / TLS接続の最初の最初の一致になるため、SNIをサポートしていないクライアントが構成したSNIサイトの数に接続しようとすると、代替サイトとして使用されます。これが発生しないようにするには、この仮想ホストの前に別の仮想ホストを作成し、SNI以外のクライアントの代替サイトとして使用してください。

おすすめ記事