Configure multi-domain name resolution in apache
Apache is one of the most popular http server software. It is famous for its fast, reliable (and stable) nature and can be expanded through simple APIs, the perl/python interpreter can be compiled to the server for free, and the source code is all open. If you have your own server or vps tutorial and do not want to purchase expensive control panels for convenience, you can configure apache yourself as a required course. The following briefly introduces how to set apache http. conf file to bind multiple domain names and their related second-level domain names (assume that the domain names we want to bind are minidx.com and ntt. cc, the second-level domain name is blog.minidx.com, and the independent ip address is 72.167.11.30 ).
How does apache bind multiple domain names?
Open http. conf
1. Change servername 127.0.0.1 to servername 72.167.11.30.
2, # modify namevirtualhost * to "namevirtualhost 72.167.11.30"
3. There is a VM format at the end of the file,
# <Virtualhost *>
# Serveradmin [email] admin@minidx.com [/email]
# Documentroot/www/httpd/html/minidx.com
# Servername minidx.com
# Errorlog logs/minidx.com-error_log
# Customlog logs/minidx.com-access_log common
# </Virtualhost>
Simple addition:
<Virtualhost 72.167.11.30>
Documentroot usr/local/www/
Servername 72.167.11.30
</Virtualhost>
<Virtualhost 72.167.11.30>
Documentroot usr/local/www/minidx.com/
Servername minidx.com
</Virtualhost>
<Virtualhost 72.167.11.30>
Documentroot usr/local/www/ntt. cc/
Servername ntt. cc
</Virtualhost>
You can also add log files in your own path.
How to add a second-level domain name in apache
In httpd. conf, you need to enable the mod_rewrite function (for details about url redirection, refer to. htaccess usage). The specific operation is to add the following content at the end of httpd. conf:
Rewriteengine on
Rewritemap lowercase int: tolower
Rewritemap vhost txt:/usr/local/etc/apache/vhost. map
Rewritecond $ {lowercase: % {server_name} ^ (. +) $
Rewritecond $ {vhost: % 1} ^ (/. *) $
Rewriterule ^/(. *) $ % 1/$1
Here,/usr/local/etc/apache is the path of your apache server configuration file, which is changed according to the actual situation (for example, under/etc/httpd ). Then, create a file: vhost. map in the directory of the path. The content is:
Www.minidx.com/usr/local/www/minidx.com
Www. ntt. cc/usr/local/www/ntt. cc
Blog.minidx.com/usr/local/www/minidx.com/blog
Finally, create the corresponding directory under the root directory/usr/local/www/of the website. To add, modify, or delete a domain name or subdomain name, you only need to change the vhost. map file without restarting the apache process.