Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to configure LINUX system apache three kinds of virtual hosts based on IP, port and domain name

Shulou Source: shulou.com Published: 2022-06-01 09:28:17 09月21日 Update

This article mainly introduces "how to configure LINUX system apache three kinds of virtual hosts based on IP, port and domain name". In daily operation, I believe many people have doubts about how to configure LINUX system apache based on IP, based on port and based on domain name. The editor consulted all kinds of materials and sorted out a simple and useful operation method, hoping to answer "how to configure LINUX system apache based on IP." The confusion of three kinds of virtual hosts based on port and domain name helps! Next, please follow the editor to study!

1. Virtual hosts based on the same IP and different Port

1) vi / etc/http/conf/httpd.conf

2) change the Listen field to

Listen 80

Listen 8888

(the above settings indicate the use of ports 80 and 8888)

3) change the virtual host section to:

DocumentRoot / var/www/html/website1

DocumentRoot / var/www/html/website2

4) Save the above settings

5) create directories and page files:

# mkdir-p / var/www/html/website1

# mkdir-p / var/www/html/website2

# cd / var/www/html/website1

# cat >; index.html; EOF

# cd / var/www/html/website2

# cat >; index.html; EOF

(note: there is DirectoryIndex index.html index.html.var in / etc/httpd/conf/httpd.conf, which means read-only index.html, but not read index.htm, remember)

6) service httpd restart

After completing the above settings, you can access it in the following ways:

1) Open the browser

2) enter http://192.168.0.1:80 and http://192.168.0.1:8888

2. Virtual hosts based on the same Port and different IP

1) configuration of different IP addresses:

# cd / etc/sysconfig/network-scripts

# cp ifcfg-eth0 ifcfg-eth0:1

# vi ifcfg-eth0:1

Change the eth0:1 to:

DEVICE=eth0:1

ONBOOT=YES

BOOTPROTO=static

IPADDR=192.168.0.2

NETMASK=255.255.255.0

2) service network restart

3) vi / etc/httpd/conf/httpd.conf

4) change the virtual host section to:

DocumentRoot / var/www/html/website1

DocumentRoot / var/www/html/website2

5) create directories and page files:

# mkdir-p / var/www/html/website1

# mkdir-p / var/www/html/website2

# cd / var/www/html/website1

# cat >; index.html; EOF

# cd / var/www/html/website2

# cat >; index.html; EOF

After completing the above settings, you can access it in the following ways:

1) Open the browser

2) enter http://192.168.0.1:80 and http://192.168.0.2:80

3. Access of virtual host based on domain name

1) vi / etc/http/conf/httpd.conf

2) change the virtual host section to:

NameVirtualHost 192.168.0.1

DocumentRoot / var/www/html/website1

ServerName www1.example.com

DocumentRoot / var/www/html/website2

ServerName www2.example.com

(note: NameVirtualHost cannot be omitted in the above settings)

3) create directories and page files:

# mkdir-p / var/www/html/website1

# mkdir-p / var/www/html/website2

# cd / var/www/html/website1

# cat >; index.html; EOF

# cd / var/www/html/website2

# cat >; index.html; EOF

4) after completing the above settings, you can access it in the following ways:

1) Open the browser

2) enter http://www1.example.com and http://www2.example.com

At this point, the study on "how to configure LINUX system apache based on IP, port and domain name-based virtual hosts" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Hosts virtual hosts domain names configurations systems learning different available through files methods browsers directories pages browsing input same more help practical next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple vpn NVidia MariaDB