
2つの異なるフォルダを指す必要があるドメインとサブドメインがあります。この記事を試しましたが、まだ問題があります。 (https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04)
www.wasamar.com.ng | wasamar.com.ng -> /var/www/html/wasamar/public
これは仮想ホストファイル(/etc/apache2/sites-available/wasamar.com.ng.conf)です。
ServerName wasamar.com.ng
ServerAlias www.wasamar.com.ng
ServerAdmin [email protected]
DocumentRoot /var/www/html/wasamar/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
www.ts.wasamar.com.ng | ts.wasamar.com.ng -> /var/www/html/wasamar_ts/public
これは仮想ホストファイル(/etc/apache2/sites-available/ts.wasamar.com.ng.conf)です。
ServerName ts.wasamar.com.ng
ServerAlias www.ts.wasamar.com.ng
ServerAdmin [email protected]
DocumentRoot /var/www/html/wasamar_ts/public/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
apache.confファイル用ペーストビンhttp://pastebin.com/dnDfB21y
どうやってこれを達成できますか?
答え1
私が知っている限り、いくつかの問題があり、おそらくそれ以上の問題があるかもしれません。まず、Apacheに各サーバーのルートディレクトリを見つけることができる場所を知らせましたが、そのディレクトリのファイルを「提供」するためのApache権限は与えませんでした。また、Apacheにこれが仮想ホストであることを知らなかった。仮想ホスト構成ファイルで実行する必要がある他の作業がありますが、少なくともサーバーディレクトリ内のファイルにApache権限を付与し、これが仮想ホスト定義であることをApacheに通知する必要があります。この最小値のみを変更すると、2つのファイルは次のようになります。
これは新しい仮想ホストファイル(/etc/apache2/sites-available/wasamar.com.ng.conf):
<VirtualHost *:80>
ServerName wasamar.com.ng
ServerAlias www.wasamar.com.ng
ServerAdmin [email protected]
DocumentRoot /var/www/html/wasamar/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# At least you need to make the folder accessable for serving by the server.
# Versions of Apache, and modules installed can make a difference in what's inside
# the Directory directive. But as an example:
<Directory "/var/www/html/wasamar_ts/public">
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
</VirtualHost>
これは新しい仮想ホストファイル(/etc/apache2/sites-available/ts.wasamar.com.ng.conf):
<VirtualHost *:80>
ServerName ts.wasamar.com.ng
ServerAlias www.ts.wasamar.com.ng
ServerAdmin [email protected]
DocumentRoot /var/www/html/wasamar_ts/public/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# At least you need to make the folder accessable for serving by the server.
# Versions of Apache, and modules installed can make a difference in what's inside
# the Directory directive. But as an example:
<Directory "/var/www/html/wasamar_ts/public">
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
</VirtualHost>
どちらの場合も、最初と最後の10行を追加することが変更されました。ディレクティブには他のものが必要な場合がOptions
ありますAllowOverride
。
これらすべてが機能するには、デフォルトのconfファイル(おそらくhttpd.conf
ディレクトリのどこかに)にいくつかのエントリを追加する必要があります/etc/apache2/
。必要なのは、これらの新しいファイルを構成に含めるディレクティブです。最も簡単にパスを指定すると、次のようになります。
Include sites-available/wasamar.com.ng.conf
Include sites-available/ts.wasamar.com.ng.conf
サイト使用可能ディレクトリに仮想ホストのみが含まれている場合は、次のものを使用できます。
Include sites-available/*.conf
これにはその場所にあるすべての.confファイルが含まれているため、毎回httpd.confに行を追加せずに必要に応じて追加のホストを作成できます。
数日間、Apacheのドキュメントを読んで、また読むと、多くのことを学ぶことができます。オンライン、またはApacheのローカルインストールに含めることもできます。たくさん見えるかもしれませんが、時間を過ごしました。