lamp配置虚拟主机(lamp搭建和配置)

lamp配置虚拟主机(lamp搭建和配置)

扫码添加渲大师小管家,免费领取渲染插件、素材、模型、教程合集大礼包!

基于端口虚拟主机配置

前面介绍了基于域名、IP的虚拟主机配置。实际生产环境中使用最多的还是基于域名的虚拟主机。今天介绍的基于端口的虚拟主机也不常用。但用的最多的场景就是:公司内网(如网站后台页面、其它发布类的页面)

基于端口的虚拟配置非常简单

默认情况http默认监听的是80端口。所以配置基于端口的虚拟主机。就是增加相应的监听端口

一:配置之前备份配置文件

[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

二:配置站点目录(方便测试不同端口)

[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

三:配置虚拟主机配置文件

1、配置前还需要到主配置文件中增加目录控制权限

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

<Directory "/data/www/bbs">

Options FollowSymLinks

AllowOverride None

Require all granted

</Directory>

增加如下配置

<Directory "/data/www/blog">

Options FollowSymLinks

AllowOverride None

Require all granted

</Directory>

实际生产环境中还是使用规范路径比较好。也可以将配置修改成如下

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

<Directory "/data/www">

Options FollowSymLinks

AllowOverride None

Require all granted

</Directory>

对上一级目录统一授权

2、主配置文件增加监听端口

[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 <URL:http://httpd.apache.org/docs/2.4/> for detailed information.

............................其中一些配置部分省略

#

#Listen 12.34.56.78:80

Listen 80

Listen 8888

Listen 9999

3、配置虚拟主机配置文件

[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 <VirtualHost> block.

#

<VirtualHost 192.168.1.20:8888>

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

</VirtualHost>

<VirtualHost 192.168.1.2:9999>

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

</VirtualHost>

4、检查配置、重启服务

[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

四:测试配置

[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

本地浏览器测试

经过测试。访问正常。表明配置正确

五:主机别名的应用

修改下刚刚的虚拟主机配置

#port bash ip

<VirtualHost 192.168.1.20:8888>

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

</VirtualHost>

#port bash name

<VirtualHost *:9999>

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

表明别名配置也是正确的

分享到 :
相关推荐

2022年SiteGround美国主机最新购买教程

SiteGround是一家知名美国主机商。成立于2004年。因其主机速度快和稳定性而...

云服务器怎么搭建宝塔(云服务器怎么搭建宝塔平台)

linux系统云服务器搭建宝塔1.访问宝塔官网。选择“linux免费版”>“[...

阿里云国际站和国内站服务器有什么不同(阿里国际站和国内站有何区别)

记得站长用的第一个服务器是韩国的KT。当时服务器的响应和速度都值得一夸。GB/s以上...

埃及服务器租用哪里有

埃及。全称为阿拉伯埃及共和国。埃及位于北非东部。领土还包括苏伊士运河以东。亚洲西南端...

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注