Skip to content

Instantly share code, notes, and snippets.

@LeeDDHH
Created January 19, 2020 14:26
Show Gist options
  • Save LeeDDHH/1830e3c50ea33dd1b394edcf180804b5 to your computer and use it in GitHub Desktop.
Save LeeDDHH/1830e3c50ea33dd1b394edcf180804b5 to your computer and use it in GitHub Desktop.

一つのIPアドレスでいくつかの名前ベースのウェブサイトを仮想ホストで実行する

httpd.confの設定

#ユーザーディレクトリを有効化
#LoadModule userdir_module libexec/apache2/mod_userdir.so
↓
LoadModule userdir_module libexec/apache2/mod_userdir.so

#Include /private/etc/apache2/extra/httpd-userdir.conf
↓
Include /private/etc/apache2/extra/httpd-userdir.conf

#バーチャルホストを有効化
#Include /private/etc/apache2/extra/httpd-vhosts.conf
↓
Include /private/etc/apache2/extra/httpd-vhosts.conf

httpd-userdir.confの設定

#Include /private/etc/apache2/users/*.conf
↓
Include /private/etc/apache2/users/*.conf

{username}.confの作成と設定

<Directory "/Users/{username}/Sites">
   Options Indexes FollowSymLinks Multiviews
   AllowOverride all
   Require all granted
</Directory>

httpd-vhost.confの設定

Listen 8080
<VirtualHost *:8080>
   DocumentRoot "/Users/{username}/Sites/{yourdocs1}"
   ServerName {yourservername1}
   <Directory "/Users/{username}/Sites/{yourdocs1}">
       Require all granted
       DirectoryIndex index.html
       Options Includes
   </Directory>
</VirtualHost>

Listen 8081
<VirtualHost *:8081>
   DocumentRoot "/Users/{username}/Sites/{yourdocs2}"
   ServerName {yourservername2}
   <Directory "/Users/{username}/Sites/{yourdocs2}">
       Require all granted
       DirectoryIndex index.html
       Options Includes
   </Directory>
</VirtualHost>

hostsファイルを編集

127.0.0.1       {yourservername1}
127.0.0.1       {yourservername2}
::1             {yourservername1}
::1             {yourservername2}

参考

Macで開発環境(Apache)の設定する方法 - Qiita

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment