Example of creating a virtual host based on Apache port

Example of creating a virtual host based on Apache port

apache: create virtual host based on port

Take creating virtual hosts (a, b, c) as an example

1) 2.1.2 Disable the default host mode

[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf
Comment out the following line in the main configuration file #DocumentRoot "/var/www/html"

2) Add the listening port in the main configuration file

Find the Listen line and add a line Listen 8080 based on the original line Listen 80 
Listen 81

3) Add port configuration virtual

[root@localhost httpd]#vim /etc/httpd/conf.d/virtualhost.conf
<VirtualHost 192.168.87.131:80>
  DocumentRoot "/var/www/a"
  ServerName www.a.com
</VirtualHost>
<VirtualHost 192.168.87.131:8080>
  DocumentRoot "/var/www/b"
  ServerName www.b.com
</VirtualHost>
<VirtualHost 192.168.87.131:81
  DocumentRoot "/var/www/c"
  ServerName www.c.com
</VirtualHost>

4) Create a new directory

[root@localhost conf.d]# cd /var/www 
[root@localhost www]# mkdir abc
[root@localhost www]# echo welcome to www.a.com >> ./a/index.html
[root@localhost www]# echo welcome to www.b.com >> ./b/index.html
[root@localhost www]# echo welcome to www.c.com >> ./c/index.html

5) Restart httpd

[root@localhost ~]#systemctl restart httpd

Note: Be sure to restart httpd!!!

Final result:

insert image description here

This is the end of this article about examples of creating virtual hosts based on Apache ports. For more information about creating virtual hosts based on Apache ports, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to add ports to Apache virtual hosts
  • Apache configuration multi-port multi-virtual host LAN access example
  • In-depth introduction to the method of configuring virtual hosts for Apache multi-port in Linux environment
  • Windows Apache multi-port virtual host configuration method

<<:  CSS Reset style reset implementation example

>>:  Vue multi-page configuration details

Recommend

JavaScript to achieve custom scroll bar effect

In actual projects, the up and down scroll bars a...

Use of hasOwnProperty method of js attribute object

Object's hasOwnProperty() method returns a Bo...

Vue implements the digital thousands separator format globally

This article example shares the specific code for...

Detailed explanation of MySQL persistent statistics

1. The significance of persistent statistical inf...

Specific usage instructions for mysql-joins

Table of contents Join syntax: 1. InnerJOIN: (Inn...

Introduction to ufw firewall in Linux

Let's take a look at ufw (Uncomplicated Firew...

How to use vue3 to build a material library

Table of contents Why do we need a material libra...

Docker Compose practice and summary

Docker Compose can realize the orchestration of D...

How to choose the right MySQL datetime type to store your time

When building a database and writing a program, i...