Help us understand the problem. What is going on with this article?

Apache の VirtualHost 設定のメモ

More than 3 years have passed since last update.

設定例

httpd.conf(または分割先の設定ファイル)に、以下のように設定する

/etc/httpd/conf.d/vhosts.conf
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName mysrv.local
    DocumentRoot /var/www/vhosts/mysrv.local/public
    ServerAdmin root@mysrv.local

    # DocumentRoot
    <Directory "/var/www/vhosts/mysrv.local/public">
        Options All
        AllowOverride All
        Require all granted
    </Directory>

    # Log
    CustomLog logs/mysrv.local/access_log combined env=!resources
    CustomLog logs/mysrv.local/resource_log combined env=resources
    CustomLog logs/mysrv.local/referer_log referer env=!is_intra_referral
    ErrorLog logs/mysrv.local/error_log

</VirtualHost>

↑ここで設定したディレクトリやログファイルは、事前に作成しておく

注意

デフォルトのサイト

前述のような設定がされている場合、デフォルトのホスト名もVirtualHost設定をする必要がある。
でないと、一番上のVirtualHost設定が適用される。
たとえば上記の設定だけがある状態でlocalhostでアクセスすると、mysrv.local にアクセスしたのと同じ動きになる

アクセス制御の書き方

Apache 2.3以降では、

    AllowOverride All
    Order allow,deny
    Allow from all

    ↑ではなく、↓のように書く (じゃないと 403 になる)

    AllowOverride All
    Require all granted
prgseek
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした