Apache Virtual Host Configuration

The company needs me to develop a remote file upload function a few days ago. It needs to install two identical systems locally and bind different domain names to transfer files. Because I haven't touched the virtual host configuration before, I couldn't get started when I was faced with the browser's error. Have to consult the technical manager, was silently thrown down a sentence: virtual host configuration is the basic skills of programmers... Then look at his series of settings, and then the system access is successful!!!

Afterwards, I checked the Apache virtual host configuration on the Internet and explained as follows:
Multiple virtual hosts can be configured on an Apache server to provide multi-site services on one server. In fact, it is to access different directories on the same server. (Multiple domain names access multiple directories)

First of all, it is stated that this operation is in the environment configuration of phpStudy, and the specific configuration needs to be based on the individual environment.

Apache configures virtual hosts based on domain names:

1. Find vhosts.conf
In phpStudy 2014, you can open it directly in the menu - open configuration file, file path: phpStudy/Apache/conf/vhosts.conf

2. Open the vhosts.conf file and modify it as follows:

<VirtualHost *:80>
    DocumentRoot "E:\phpStudy\WWW\newhouse\web"
    ServerName app.08cms.com
    <Directory "E:\phpStudy\WWW\newhouse\web">
        Options FollowSymLinks ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "E:\phpStudy\WWW\newimage\web"
    ServerName img.08cms.com
    <Directory "E:\phpStudy\WWW\newimage\web">
        Options FollowSymLinks ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

Two virtual hosts are configured here. Both hosts use 80 ports. The first one is named "app.08cms.com", the server directory is "E: phpStudy WWW newhouse web", the second one is named "img.08cms.com" and the server directory is "E: phpStudy WWW\ new web".

According to the information on the internet, the default virtual host can be configured as the first one, and the domain name access of the virtual host can not be found is also provided by the virtual host.

3. Find hosts
In phpResearch 2014, you can open it directly in [menu-open hosts], file path: Windows/System32/drivers/etc/hosts

4. Open hosts and modify them as follows:

127.0.0.1 app.08cms.com
127.0.0.1 img.08cms.com

Note: If you are only doing configuration testing locally, you need to add domain name mapping to the local IP address in the hosts file. So 3, 4 according to the actual situation.

5. Restart Apache and access the system successfully!

Second, Apache configures virtual hosts based on ports (to be tested):

1. First, modify the configuration in the Apache configuration file conf/httpd.conf to allow the Apache server to listen on multiple ports:

  Listen 8080

  Listen 80

Here, two ports are monitored and two virtual hosts are configured.

2. Then add the following configuration information in the configuration file conf/vhosts.conf:

<VirtualHost *:80>
    DocumentRoot "E:\phpStudy\WWW\newhouse\web"
    ServerName app.08cms.com
    <Directory "E:\phpStudy\WWW\newhouse\web">
        Options FollowSymLinks ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:800>
    DocumentRoot "E:\phpStudy\WWW\newimage\web"
    ServerName img.08cms.com
    <Directory "E:\phpStudy\WWW\newimage\web">
        Options FollowSymLinks ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

Finally, by restarting the Apache server, you can access two different directories on the same server through different ports of the same IP address.

Note: Web servers use port 80 by default, so you don't need to add ": 80" when accessing the site of port 80, but you must bring port number when accessing other ports.

The configuration in the segment can cover the external configuration.

Reference website:

http://www.it165.net/admin/html/201502/4903.html

http://www.cnblogs.com/lucky-man/p/6207851.html

http://www.tuicool.com/articles/n2uYBb

Keywords: Apache Windows

Added by stewart715 on Fri, 14 Jun 2019 04:09:01 +0300