Apache domain name binding

  
                  

Apache is one of the most popular HTTP server software, it is known for being fast, reliable (stable), and with a simple API extension, the Perl/Python interpreter can be compiled into the server, completely free, and source The code is all open. If you have your own server or VPS and don't want to buy expensive control panels for convenience, then configuring your own Apache is a compulsory course. The following is a brief introduction to how to bind multiple domain names and their associated second-level domain names by setting Apache's http.conf file (assuming that the domain names we want to bind are 45it.com and 45it.com, the second-level domain name is Blog.45it.com, independent IP is 72.167.11.30).

How to bind multiple domain names to apache Open http.conf 1, ServerName 127.0.0.1 Modified to ServerName 72.167.11.30 2, #NameVirtualHost * Modified into "NameVirtualHost 72.167.11.30" 3, there is a virtual host format at the end of the file, #<VirtualHost *> # ServerAdmin [email][email protected][/email] # DocumentRoot /www/httpd/html/45it .com # ServerName 45it.com # ErrorLog logs/45it.com-error_log # CustomLog logs/45it.com-access_log common #</VirtualHost> Simply add: <VirtualHost 72.167.11.30> DocumentRoot usr/local/www /ServerName 72.167.11.30 </VirtualHost> <VirtualHost 72.167.11.30> DocumentRoot usr/local/www/45it.com/ServerName 45it.com </VirtualHost> <VirtualHost 72.167.11.30> D ocumentRoot usr/local/www/45it.com/ServerName 45it.com </VirtualHost>

Log files can also be added according to their own path.

How Apache adds second-level domain name

httpd.conf needs to open mod_rewrite function (for specific instructions on URL redirection, you can refer to the .htaccess usage method summary), the specific operation is, in httpd At the end of the .conf, add the following:

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

where /usr/local/etc/apache is yours The path of the apache server configuration file is changed according to the actual situation (for example, under /etc/httpd/). Then, create a file in the directory of the path: vhost.map, the content is:

www.45it.com /usr/local/www/45it.com www.45it.com /usr/local /www/45it.com blog.45it.com /usr/local/www/45it.com/blog

Finally, in the root directory of the website /usr/local/www/, create the corresponding directory. . If you need to add, modify or delete the domain name, subdomain, just change the vhost.map file without restarting the apache process.

Copyright © Windows knowledge All Rights Reserved