Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report