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

Example Analysis of Port-based Virtual Host configuration of Apache Service in LAMP Architecture

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you the "sample analysis of port-based virtual host configuration of Apache services in LAMP architecture", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and study the "sample analysis of port-based virtual host configuration of Apache services in LAMP architecture".

Port-based virtual host configuration

The virtual host configuration based on domain name and IP was introduced earlier. In the actual production environment, the virtual host based on domain name is the most used. The port-based virtual host introduced today is not commonly used, but the most frequently used scenario is: the company intranet (such as the background page of the website and the pages of other publishing classes).

Port-based virtual configuration is very simple

By default, http listens to port 80 by default, so to configure a port-based virtual host is to add a corresponding listening port.

One: back up the configuration file before configuration

[root@Centos extra] # cp httpd-vhosts.conf httpd-vhosts.conf.$ (date +% F)

[root@Centos extra] # ls

Httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf

Httpd-vhosts.conf httpd-vhosts.conf.2016-09-09

Httpd-default.conf httpd-manual.conf httpd-ssl.conf proxy-html.conf

Second: configure the site directory (to facilitate testing different ports)

[root@Centos extra] # mkdir-p / data/www/blog/

[root@Centos extra] # echo "welcome to the server of blogs" > > / data/www/blog/index.html

[root@Centos extra] # cat / data/www/blog/index.html

Welcome to the server of blogs

Three: configure the virtual host profile

1. Directory control permissions need to be added to the main configuration file before configuration.

[root@Centos extra] # vi.. / httpd.conf

Options FollowSymLinks

AllowOverride None

Require all granted

Add the following configuration

Options FollowSymLinks

AllowOverride None

Require all granted

In the actual production environment, it is better to use the standard path, or you can modify the configuration as follows

[root@Centos extra] # vi.. / httpd.conf

Options FollowSymLinks

AllowOverride None

Require all granted

Unified authorization of the directory at the next level

2. Add listening ports to the main configuration file

[root@Centos extra] # vi.. / httpd.conf

#

# This is the main Apache HTTP server configuration file. It contains the

# configuration directives that give the server its instructions.

# See for detailed information.

.. Some of the configurations are omitted.

#

# Listen 12.34.56.78:80

Listen 80

Listen 8888

Listen 9999

3. Configure the virtual host configuration file

[root@Centos extra] # vi httpd-vhosts.conf

# Virtual Hosts

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any block.

#

ServerAdmin admini@abc.com

DocumentRoot "/ data/www/bbs"

ServerName 192.168.1.20

ServerAlias abc.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

ServerAdmin admini@abc.com

DocumentRoot "/ data/www/blog"

ServerName 192.168.1.2

ServerAlias abc.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

4. Check the configuration and restart the service

[root@Centos extra] #.. /.. / bin/apachectl-t

Syntax OK

[root@Centos extra] #.. /.. / bin/apachectl graceful

[root@Centos extra] # ps-ef | grep http

Root 23901019 graceful 42? 00:00:00 / application/apache2.4.23/bin/httpd-k graceful

Daemon 2725 2390 0 20:33? 00:00:00 / application/apache2.4.23/bin/httpd-k graceful

Daemon 2726 2390 0 20:33? 00:00:00 / application/apache2.4.23/bin/httpd-k graceful

Daemon 2727 2390 0 20:33? 00:00:00 / application/apache2.4.23/bin/httpd-k graceful

Root 2835 1934 0 20:39 pts/1 00:00:00 grep http

[root@Centos extra] # netstat-lnt | grep 8888

Tcp 0 0: 8888: * LISTEN

[root@Centos extra] # netstat-lnt | grep 9999

Tcp 0 0: 9999: * LISTEN

Four: test the configuration

[root@Centos extra] # cat / data/www/bbs/index.html

Welcome to bbs.abc.com

192.168.1.20:80 this server is the server of bbs stie

[root@Centos extra] # cat / data/www/blog/index.html

Welcome to the server of blogs

Local browser test

After testing, the access is normal, indicating that the configuration is correct.

Five: the application of host alias

Modify the virtual host configuration just now

# port bash ip

ServerAdmin admini@abc.com

DocumentRoot "/ data/www/bbs"

ServerName 192.168.1.20

ServerAlias abc.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

# port bash name

ServerAdmin admini@abc.com

DocumentRoot "/ data/www/blog"

ServerName blog.abc.com

ServerAlias blog1.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

[root@Centos extra] #.. /.. / bin/apachectl-t

Syntax OK

[root@Centos extra] #.. /.. / bin/apachectl graceful

Indicates that the alias configuration is also correct

These are all the contents of the article "sample analysis of port-based virtual host configuration of Apache services in LAMP architecture". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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