Create multiple sites (different domain names) on one Apache server

Source: Internet
Author: User
Tags aliases

Use different domain names to differentiate different sites, all of which refer to the same IP address. Apache uses the host parameter included with the HTTP header to determine which Web site a user needs to visit.

For example, to set up the following two sites on a single server:

    • Http://www.test1.com
    • Http://www.test1.com
The following is an example of a CentOS 7.2 system that details how to configure an Apache virtual host based on a different domain name. First step: Open Apache's Vhost module

In the http.conf configuration file, locate the following line of code, delete the previous # number, and open the Vhost module.

# LoadModule vhost_alias_module modules/mod_vhost_alias.so
Step Two: Create a new vhost.conf in the Apache configuration folder to use as a configuration file for the virtual host set the Site directory to /webdata by defaultAdd the following configuration (in the same vhost.conf ) to the actual situation:
1<virtualhost *:80>#listening on port 802ServerAdmin [email protected]#Webmaster Contact Information3DocumentRoot"/webdata/test1"              #Site Directory4ServerName www.test1.com#site domain name, used to identify different websites5Serveralias test1.com#aliases6Errorlog"Logs/test1-error.log"            #Error log path7Customlog"Logs/test1-access.log"Common#Access Log Path8</VirtualHost>9 Ten<virtualhost *:80>#listening on port 80 OneServerAdmin [email protected]#Webmaster Contact Information ADocumentRoot"/webdata/test2"              #Site Directory -ServerName www.test2.com#site domain name, used to identify different websites -Serveralias test2.com#aliases theErrorlog"Logs/test2-error.log"            #Error log path -Customlog"Logs/test2-access.log"Common#Access Log Path -</VirtualHost>
here only two domain name information is configured, the number of sites on the server, configure how many copies of the above information, and according to the actual situation to modify the content. add a line of include/etc/httpd/conf/vhost.confto the http.conf file to include the contents of the vhost.conf file. Step three: Bind the domain name of the site to the local loopback address in the /etc/hosts file (add the following information at the end of the hosts file)
1 127.0.0.1 www.test1.com2 127.0.0.1 www.test2.com
Fourth step: restartReload The configuration file using the service httpd Reload command, or restart the Apache process using the service httpd restart command.
Finally, the domain name is resolved to the server, different domain names have successfully visited different site content. The following is an example of wampserver3.1.0 to configure a multisite server locally on WindowsFirst step: Open Apache's Vhost moduleIn the http.conf configuration file, locate the following line of code, delete the previous # number, and open the Vhost module.
# LoadModule vhost_alias_module modules/mod_vhost_alias.so

Step Two: Create a new vhost.conf in the Apache configuration folder, which is used as the configuration file for the virtual host.

set the Site directory to d:/wamp64/www/test1 by defaultAdd the following configuration (in the same vhost.conf ) to the actual situation:
1<virtualhost 127.0.0.1:80>#listening on port 802ServerAdmin [email protected]#Webmaster Contact Information3DocumentRoot"D:/wamp64/www/test1"         #Site Directory4ServerName 127.0.0.1#site domain name, used to identify different websites5Serveralias 127.0.0.1#aliases6Errorlog"Logs/test1-error.log"            #Error log path7Customlog"Logs/test1-access.log"Common#Access Log Path8</VirtualHost>9 Ten<virtualhost 127.0.0.2:80>#listening on port 80 OneServerAdmin [email protected]#Webmaster Contact Information ADocumentRoot"D:/wamp64/www/test2"        #Site Directory -ServerName 127.0.0.2#site domain name, used to identify different websites -Errorlog"Logs/test2-error.log"           #Error log path theCustomlog"Logs/test2-access.log"Common#Access Log Path -</VirtualHost>
here only two domain name information is configured, the number of sites on the server, configure how many copies of the above information, and according to the actual situation to modify the content. add a line of include/etc/httpd/conf/vhost.confto the http.conf file to include the contents of the vhost.conf file. Step three: Restart the server

Create multiple sites (different domain names) on one Apache server

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.