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

Solution to the problem that docker nginx cannot be accessed after running

## 1 I'm learning docker deployment recently,...

MySQL password is correct but cannot log in locally -1045

MySQL password is correct but cannot log in local...

Detailed description of the function of new in JS

Table of contents 1. Example 2. Create 100 soldie...

js realizes the image cutting function

This article example shares the specific code of ...

Detailed explanation of how to use several timers in CocosCreator

1. setTimeOut Print abc after 3 seconds. Execute ...

Vue implements form data validation example code

Add rules to the el-form form: Define rules in da...

Detailed explanation of vue.js dynamic components

:is dynamic component Use v-bind:is="compone...

HTML basics summary recommendation (paragraph)

HTML Paragraph Paragraphs are defined by the <...

A few things about favicon.ico (it’s best to put it in the root directory)

Open any web page: for example, http://www.baidu....

How to implement draggable components in Vue

This article shares with you how to implement dra...

Reasons and solutions for slow MySQL query stuck in sending data

Because I wrote a Python program and intensively ...