LoginSignup
12
12

More than 5 years have passed since last update.

yosemiteでapacheのvhost設定をする(ついでにRubyも動くようにしとく)

Last updated at Posted at 2014-10-22

ほぼクリーンなyosemiteで、apacheを立ち上げてvhostも設定した時に最初にしたこと。

まずは設定ファイルの場所

apache設定ファイル

/private/etc/apache2/httpd.conf

vhost用のインクルード設定ファイル

/private/etc/apache2/extra/httpd-vhosts.conf

hostファイル

/private/etc/hosts

やったこと

vhosts.confを読み込み

httpd.conf499行目付近の

#Include /private/etc/apache2/extra/httpd-vhosts.conf

のコメントを外す

vhostsの設定ファイルを編集

httpd-vhosts.confを編集する。最低限以下のような感じ?

# domainnameと/path/to/your/docs/は各自環境で読み替え

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/path/to/your/docs/"
    ServerName domainnameA
    <Directory "/path/to/your/docs/">
        Require all granted
        DirectoryIndex index.html
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/path/to/your/another/docs/"
    ServerName domainnameB
    <Directory "/path/to/your/another/docs/">
        Require all granted
        DirectoryIndex index.html
    </Directory>
</VirtualHost>

ここ参考にさせていただきました。
http://blog.77jp.net/authz_coreerror-apache-2-4-error
http://www.adminweb.jp/apache/virtual/index2.html

hostsを編集

127.0.0.1 localhost
# 以下を追記。domainnameは各自環境で読み替え
127.0.0.1 domainnameA
127.0.0.1 domainnameB

で、apache再起動

sudo apachectl restart

Ruby動かす

モジュールの読み込み

httpd.conf157行目付近の

#Loadmodule cgi_module libexec/apache2/mod_cgi.so

のコメントを外す

vhosts.confに以下を追記

    <Directory "/path/to/your/docs/">
        Require all granted
        #以下追記
        DirectoryIndex index.html index.rb
        Options +ExecCGI
        AddHandler cgi-script .rb
    </Directory>

同じくapache再起動は忘れずに。


すべて、「とりあえず動かす」レベルなので、必要な設定はそれぞれあとから追記すれば良いかなと。

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12