LAMP架构应用实战—Apache服务基于端口虚拟主机配置
2020-12-20 03:36
标签:block 长按 二维 netstat example 介绍 not mkdir fir 前面介绍了基于域名、IP的虚拟主机配置,实际生产环境中使用最多的还是基于域名的虚拟主机,今天介绍的基于端口的虚拟主机也不常用,但用的最多的场景就是:公司内网(如网站后台页面、其它发布类的页面) [root@Centos extra]# cp httpd-vhosts.conf httpd-vhosts.conf.$(date +%F) [root@Centos extra]# mkdir -p /data/www/blog/ 1、配置前还需要到主配置文件中增加目录控制权限 2、主配置文件增加监听端口 This is the main Apache HTTP server configuration file. It contains the #Listen 12.34.56.78:80 3、配置虚拟主机配置文件 VirtualHost example: 4、检查配置、重启服务 [root@Centos extra]# cat /data/www/bbs/index.html 修改下刚刚的虚拟主机配置 LAMP架构应用实战—Apache服务基于端口虚拟主机配置 标签:block 长按 二维 netstat example 介绍 not mkdir fir 原文地址:https://blog.51cto.com/mingongge/2555695LAMP架构应用实战—Apache服务
基于端口虚拟主机配置
基于端口的虚拟配置非常简单
默认情况http默认监听的是80端口,所以配置基于端口的虚拟主机,就是增加相应的监听端口一:配置之前备份配置文件
[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二:配置站点目录(方便测试不同端口)
[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三:配置虚拟主机配置文件
[root@Centos extra]# vi ../httpd.conf
Options FollowSymLinks
AllowOverride None
Require all granted
增加如下配置
Options FollowSymLinks
AllowOverride None
Require all granted
实际生产环境中还是使用规范路径比较好,也可以将配置修改成如下
[root@Centos extra]# vi ../httpd.conf
Options FollowSymLinks
AllowOverride None
Require all granted
对上一级目录统一授权
[root@Centos extra]# vi ../httpd.conf
configuration directives that give the server its instructions.
See
Listen 80
Listen 8888
Listen 9999
[root@Centos extra]# vi httpd-vhosts.conf
Virtual Hosts
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
#
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
[root@Centos extra]# ../../bin/apachectl -t
Syntax OK
[root@Centos extra]# ../../bin/apachectl graceful
[root@Centos extra]# ps -ef |grep http
root 23901019: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 四:测试配置
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
本地浏览器测试
经过测试,访问正常,表明配置正确五:主机别名的应用
#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
表明别名配置也是正确的
长按二维码图片关注微信公众号
文章标题:LAMP架构应用实战—Apache服务基于端口虚拟主机配置
文章链接:http://soscw.com/essay/37344.html