HTTPD Virtual host configuration based on different domain names

Source: Internet
Author: User

apache2.2.x version

1. Note The doucumentroot in the master configuration file/etc/httpd/conf/httpd.conf

" /var/www/html "

2. Remove the main configuration file namevirtualhost the previous comment, add the local host name

192.168. 136.131:

3. If the servername is commented, or the default is localahost:80 or 127.0.0.1:80, it will be an error, but does not affect the use of the virtual host

" stopping httpd:                                            [  OK  ]starting httpd:httpd:Could not reliably determine the server's fully qualified domain NA Me, using:: 1 for ServerName                                                           [  OK  ]

4. Add a configuration file for the virtual host below the Master profile

<virtualhost192.168.136.131: the>//Local Host name, this user-authenticated loginDocumentroot/var/www/virtual/test1//Site root directoryServerName www.test1.com//Domain 1Errorlog logs/error_logs//Error Log AddressCustomlog Logs/custom_logs combined//General log, combined type record<Directory/var/www/virtual/test1/>//Configure Site Directory permissionsOptions none#allowoverride None allowoverride authconfig//Add Base user Authentication login configurationauthtype Basic AuthName"Test"AuthUserFile"/etc/httpd/conf/htpasswd"  //Authentication User Password storage locationRequire User Test//allow only Test loginOrder Allow,deny//allow all users to access allow from all</directory></virtualhost><virtualhost192.168.136.131: the>//General ConfigurationServerAdmin [email protected]//Domain 2documentroot/var/www/virtual/test2/ServerName www.test2.com errorlog logs/Error_logs</VirtualHost>

Then restart httpd

httpd2.4.x version

1. The main configuration file only need to virtualhost the following incalude line to remove comments

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

2. Configure/etc/httpd/extra/httpd-vhost.conf

 

<virtualhost *: the>//Do not fill in 127.0.0.1 or localhost here, you can use the "*" or the local network IP extranet IPServerAdmin [email protected] documentroot"/usr/local/apache/htdocs/www.a.org"ServerName"www.a.org"directoryindex index.html index.php errorlog"Logs/www.a.org-error_log"Customlog"Logs/www.a.org-access_log"combined</virtualhost><virtualhost *: the>ServerAdmin [email protected] documentroot"/usr/local/apache/htdocs/www.b.org"ServerName"www.b.org"directoryindex index.html index.php errorlog"Logs/www.b.org-error_log"Customlog"Logs/www.b.org-access_log"combined</VirtualHost>

3. Restart the service

HTTPD Virtual host configuration based on different domain names

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.