虚拟服务器如何改host,虚拟主机 Virtual Host 的设置

一、应用场景

+--------------+----------------+---------------------+

| 域名 | 主机ip | 对应的主目录 |

+--------------+----------------+---------------------+

| www.100.com |192.168.80.135 | /var/www/html |

| bbs.100.com |192.168.80.135 | /var/www/html/bbs |

| sns.100.com |192.168.80.135 | /var/www/html/sns |

| ftp.100.com |192.168.80.135 | /var/www/ftp |

+--------------+----------------+---------------------+

二、实现

# vim /etc/httpd/conf.d/virtual.conf

#本机任何页面的 port 80 所指定的虚拟主机

NameVirtualHost *:80

#设置www.100.com

#:针对目录浏览权限的设置

#:对documentRoot、customlog(日志目录)进行设置

options Followsymlinks

allowoverride none

order allow,deny

allow from all

serverName www.100.com

documentroot /var/www/html

customlog /var/log/httpd/www.access_log combined

#设置sns.100.com

Options FollowSymLinks

AllowOverride None

Order allow,deny

allow from all

serverName sns.100.com

documentRoot /var/www/html/sns

customlog /var/log/httpd/sns.access_log combined

#设置bbs.100.com

Options FollowSymLinks

AllowOverride None

Order allow,deny

allow from all

servername bbs.100.com

documentroot /var/www/html/bbs

customlog /var/log/httpd/bbs.access_log combined

# 设置ftp.100.com

options Indexes FollowSymlinks

allowoverride none

order allow,deny

allow from all

servername ftp.100.com

documentroot /var/www/ftp

customlog /var/log/httpd/ftp.access_log combined

ErrorLog /var/log/httpd/ftp.error_log combined

三、注意事项

在虚拟主机的设置中,还有很多可用的功能,不过,最低的限度是需要ServerName以及documentRoot。

使用了虚拟主机后,原本的主机名称www.100.com也要同时写入到对应的虚拟主机中,否则这个主机域名可能将不知道去向。

CustomLog表示向对应主机访问时,日志将被写入到该文件中。但这个新增的日志必须要加入到logrotate的管理文件中,否则日志文件将会超级大。

ErrorLog表示错误日志

# cd /etc/logrotate.d/

# vim httpd

/var/log/httpd/*log {

missingok

notifempty

compress

sharedscripts

delaycompress

postrotate

/sbin/service httpd reload > /dev/null 2>/dev/null || true

endscript

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值