说明:
Apache版本:httpd-2.2.31
Apache安装目录:/usr/local/apache
目的:
配置Apache虚拟主机
具体操作:
1、修改Apache主配置文件
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf-bak #修改之前先备份
vi /usr/local/apache/conf/httpd.conf #修改
找到# Virtual hosts这一行,添加以下两行:
Include conf/error/*.conf
Include conf/vhost/*.conf
找到# Server-pool management (MPM specific)这一行,取消下面一行的注释
Include conf/extra/httpd-mpm.conf
找到#ErrorDocument 404 /404.html这一行,取消前面的注释
ErrorDocument 404 /404.html #404.html需要创建好放在网站根目录下面
找到# ErrorLog: The location of the error log file.这一段,添加
ErrorLog "/usr/local/apache/logs/error_log" #Apache错误日志记录,需要创建好目录文件
#ErrorLog "/dev/null" #表示不记录Apache错误日志
LogLevel crit #日志级别,致命情况才记录
找到# The location and format of the access logfile (Common Logfile Format).这一段,添加
CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/access_log%Y%m%d.log 86400 480" combined #按天保存Apache访问日志记录
:wq! #保存退出
系统运维 www.iyunv.com 温馨提醒:系统运维原创内容版权所有,转载请注明出处及原文链接
2、创建虚拟主机配置文件存放目录
cd /usr/local/apache/conf
mkdir vhost #创建虚拟主机存放目录
mkdir error #创建空主机头存放目录
3、禁止Apache空主机头设置
cd /usr/local/apache/conf/error
vi error.iyunv.com.conf #编辑
NameVirtualHost *:80
ServerAdmin yourmail@mail.com
DocumentRoot /tmp
ServerName error
:wq! #保存退出
4、添加虚拟主机配置文件
cd /usr/local/apache/conf/vhost
vi bbs.iyunv.com.conf #编辑
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /home/web/osyunwi.com/bbs.iyunv.com/
ServerName bbs.iyunv.com
ServerAlias bbs.iyunv.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/iyunv.com/bbs.iyunv.com/access_log%Y%m%d.log 86400 480" combined #访问日志,目录文件需要提前创建好
DirectoryIndex index.htm index.html index.php
php_admin_value open_basedir "/home/web/osyunwi.com/bbs.iyunv.com/:/tmp/" #防止php***跨站
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
:wq! #保存退出
vi sns.iyunv.com.conf #编辑
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /home/web/osyunwi.com/sns.iyunv.com/
ServerName sns.iyunv.com
ServerAlias sns.iyunv.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/iyunv.com/sns.iyunv.com/access_log%Y%m%d.log 86400 480" combined #访问日志,目录文件需要提前创建好
DirectoryIndex index.htm index.html index.php
php_admin_value open_basedir "/home/web/osyunwi.com/sns.iyunv.com/:/tmp/" #防止php***跨站
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
:wq! #保存退出
5、重启Apache
service httpd restart #重启
至此,Linux下Apache虚拟主机配置教程完成。
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com