LoginSignup
12
12

More than 5 years have passed since last update.

Homebrewでdnsmasqをインストールして、Web開発用にDNSサーバを立てる

Posted at

dnsmasqでDNSサーバを立てて、動的にバーチャルホストを設定する。

環境

  • Mac OSX 10.8.2
  • Homebrew
  • dnsmasq 2.65

インストール

brew install dnsmasq

dnsmasqの設定

設定ファイルをコピーする。

$  /usr/local/Cellar/dnsmasq/2.65/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

以下をdnsmasq.confに追記

listen-address=127.0.0.1
address=/.dev/127.0.0.1

起動

sudo cp `brew --prefix dnsmasq`/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

確認

host hoge.dev
hoge.dev has address 127.0.0.1

apacheの設定

<Virtualhost *:80>
    VirtualDocumentRoot "/path/to/your/workspace/%1"
    ServerName vhosts.dev
    ServerAlias *.dev
    UseCanonicalName Off
    <Directory "/path/to/your/workspace/%1">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</Virtualhost>

毎回プロジェクト毎に"xxx.dev"のようなドメインでアクセスできるように、httpd.confとhostsファイルを設定していたけど、これで設定の必要がなくなる。
プロジェクト毎にフォルダ構成が違ったりドキュメントルートが違ったりする場合は、適当にフォルダ作ってアクセスしたいサブドメイン名でシンボリックリンクをそのフォルダに作ればいい。

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