How to build multiple websites on one server (Apache version)

The configuration file of Apache is generally placed in the /etc/httpd/conf folder. httpd.conf is its main configuration file. When configuring, you can configure the configuration file of the virtual host separately, for example, name it vhost.conf, and then Add a line containing the statement "Include /etc/httpd/conf/vhost.conf" to http.conf to include the vhost.conf configuration file.

 

At present, the methods for building multiple websites on one server mainly include the following:
1. This method based on IP address
is suitable for the situation where one server has multiple IP addresses, but currently, Alibaba Cloud ECS only allows binding to one public website. Network IP and a private network IP, so this method is not applicable
2. Based on port number
This method uses different port numbers to identify different websites, and the actual access is realized by using the URL plus the port number, such as http://port .huigher.cn:80 , http://port.huigher.cn:81 , http://port.huigher.cn:82 , after this method is configured, you need to add the port number after the website to access different websites. Due to the shortage of website domain names but the sufficient port number of the server, the disadvantage is that the port number needs to be added after the website, which is not conducive to user access . 3. This method uses different domain names to distinguish different websites
based on the host name .
Pointing to the same IP, Apache uses the host parameter attached to the HTTP header to determine which website the user needs to visit, such as http://test1.huigher.cn , http://test2.huigher.cn , http://test3 .huigher.cn . In most cases, multiple websites use this method on one server. The following takes CentOS6.5 system as an example to explain how to configure Apache virtual host based on host name.

1. Create a new vhost.conf in the Apache configuration folder as the configuration file of the virtual host, write the content of the virtual host in it, and add the default file header first:

 


NameVirtualHost *:80

    ServerName *
    # DocumentRoot is the directory of the website by default
    DocumentRoot /www/html


2. Then add the following configuration according to the actual situation:

 


#Listen for HTTP requests on port 80 on any address

    #Website administrator contact information
    ServerAdmin

[email protected] #The
    directory of the website
    DocumentRoot /var/www/html/test3 #Host
    name, apache uses this address to identify different websites
    ServerName test3.huigher.cn #Error
     log path
    ErrorLog logs/test3.huigher.cn -error_log #Access
    log path
    CustomLog logs/test3.higher.cn-access_log common


4. How many websites are on the server, then configure how many copies of the above information, and modify the content according to the actual situation. The page configuration on the server during the test is as follows:

z1-1.JPG

 

5. Add a line of "Include /etc/httpd/conf/vhost.conf" to the http.conf file to include the content of the vhost.conf file

 

6. Bind the domain name of the website to the local loopback address in the /etc/hosts file:

127.0.0.1 test1.huigher.cn

127.0.0.1 test2.huigher.cn

127.0.0.1 test3.huigher.cn


七、 最后使用service httpd reload重新加载配置文件或service httpd restart重启Apache进程即可


八、 测试不同的域名返回了不同的网站内容

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324889473&siteId=291194637
Recommended