joppot

The program absolutely runs in copy paste

mac

Set up subdomain for each directory using virtual host of apache 2.4 and Mac hosts

投稿日:2017年3月12日 更新日:

Pocket

topthumbsubdoman

Abstract

Hello everybody, It’s candle.
This time I will show you how to divide directories by subdomain with mac easily.

For example, it is useful when such situation.
If you are developing some wordpress project with apache, there are URL like the following.

http://localhost:8080/workspace/alice_blog/index.html
http://localhost:8080/workspace/tom_service/index.html

It is the long URL.
If you choose this article way,

http://alice.localhost:8080/index.html
http://tom.localhost:8080/index.html

you can make the above URL.

Premise

mac
apache2.4
Sample project

SPONSORED LINK


setting for hosts

First, you write the subdomain which you want to use to hosts file.

Open the /etc/hosts, in general, it is described as follows.

127.0.0.1 [sub domain name]

127.0.0.1 is your own pc address, that is the local host.
In this time, we describe like this.

127.0.0.1 alice.localhost

hostsubdomain

Save it.
The sub domain setting is over.

Setting apache’s virtual host

We set up apache side.
There is a configuration file in the following path when you install apache 2.4 by brew.

/usr/local/etc/apache2/2.4/httpd.conf

Add this.

<VirtualHost *:8080>
  ServerName alice.localhost
  DocumentRoot /Users/candle/apache/alice_blog
  <Directory "/Users/candle/apache/alice_blog">
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

alicelocal

Please change the port number 8080 to your own setting.
Write the subdomain you set before in ServerName.
Specify the location you want to be root when accessing url with DocumentRoot and .

Save it.

Check with the browser

Let’s start apache server and check it.
Apache installed with brew, start it with the fllowing command.

httpd -k start

You try to access the URL which is setting in hosts and apache.

http://alice.locahost:8080

youcanacessaliceblog

Access succeeded.


Conclusion

This apache configuration is a setting for development only locally, we do not consider security etc.
Please be careful about migration to the production environment.

スポンサードリンク

If you think this article is good, share it please

-mac
-,

執筆者:


comment

Your email address will not be published. Required fields are marked *

関連記事

関連記事はありませんでした

Profile


I work in the venture company as a CTO. I start to write programing in University, first I learned java, C++ and PHP. In the company, I'm developing web services by Rails. I do like to automation.

twitter

スポンサードリンク

Archives