幫助中心
這里有最新的使用文檔和教程
Linux下Apache虛擬主機(jī)配置
說(shuō)明:
Apache版本:httpd-2.2.31
Apache安裝目錄:/usr/local/apache
目的:
配置Apache虛擬主機(jī)
具體操作:
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需要?jiǎng)?chuàng)建好放在網(wǎng)站根目錄下面
找到# ErrorLog: The location of the error log file.這一段,添加
ErrorLog "/usr/local/apache/logs/error_log" #Apache錯(cuò)誤日志記錄,需要?jiǎng)?chuàng)建好目錄文件
#ErrorLog "/dev/null" #表示不記錄Apache錯(cuò)誤日志
LogLevel crit #日志級(jí)別,致命情況才記錄
找到# 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訪問(wèn)日志記錄
:wq! #保存退出
系統(tǒng)運(yùn)維 www.osyunwei.com 溫馨提醒:系統(tǒng)運(yùn)維原創(chuàng)內(nèi)容©版權(quán)所有,轉(zhuǎn)載請(qǐng)注明出處及原文鏈接
2、創(chuàng)建虛擬主機(jī)配置文件存放目錄
cd /usr/local/apache/conf
mkdir vhost #創(chuàng)建虛擬主機(jī)存放目錄
mkdir error #創(chuàng)建空主機(jī)頭存放目錄
3、禁止Apache空主機(jī)頭設(shè)置
cd /usr/local/apache/conf/error
vi error.osyunwei.com.conf #編輯
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin yourmail@mail.com
DocumentRoot /tmp
ServerName error
</VirtualHost>
:wq! #保存退出
4、添加虛擬主機(jī)配置文件
cd /usr/local/apache/conf/vhost
vi bbs.osyunwei.com.conf #編輯
<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /home/web/osyunwi.com/bbs.osyunwei.com/
ServerName bbs.osyunwei.com
ServerAlias bbs.osyunwei.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/osyunwei.com/bbs.osyunwei.com/access_log%Y%m%d.log 86400 480" combined #訪問(wèn)日志,目錄文件需要提前創(chuàng)建好
DirectoryIndex index.htm index.html index.php
<Directory "/home/web/osyunwi.com/bbs.osyunwei.com/">
php_admin_value open_basedir "/home/web/osyunwi.com/bbs.osyunwei.com/:/tmp/" #防止php木馬跨站
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
:wq! #保存退出
vi sns.osyunwei.com.conf #編輯
<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /home/web/osyunwi.com/sns.osyunwei.com/
ServerName sns.osyunwei.com
ServerAlias sns.osyunwei.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/osyunwei.com/sns.osyunwei.com/access_log%Y%m%d.log 86400 480" combined #訪問(wèn)日志,目錄文件需要提前創(chuàng)建好
DirectoryIndex index.htm index.html index.php
<Directory "/home/web/osyunwi.com/sns.osyunwei.com/">
php_admin_value open_basedir "/home/web/osyunwi.com/sns.osyunwei.com/:/tmp/" #防止php木馬跨站
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
:wq! #保存退出
5、重啟Apache
service httpd restart #重啟
至此,Linux下Apache虛擬主機(jī)配置教程完成。