更改Apache运行账户以及建立虚拟主机
1. 更改Apache运行账户默认情况下Apache在Linux系统上使用nobody账户运行,我们下面将要更改运行账户提升Apache的安全性和权限可控性。
CODE:
# useradd www
# su www $ mkdir -p /home/www/wwwroot/discuz $ exit # vi /usr/local/apache2/conf/httpd.conf |
找到:
CODE:
User nobody
Group #-1 |
改为:
CODE:
User www
Group www |
2. 建立一个虚拟主机此处我们为Apache建立一个虚拟主机。
CODE:
# vi /usr/local/apache2/conf/httpd.conf
|
找到:
CODE:
#NameVirtualHost *
|
去调前面的“#”号以打开注释,使用虚拟主机模式运行Apache。在该配置文件的末尾添加一个虚拟主机,且该虚拟主机日志文件存放目录为/home/www/logs
CODE:
<VirtualHost *>
ServerName www.your-domain.com DocumentRoot /home/www/wwwroot/discuz ErrorLog /home/www/logs/discuz-error_log CustomLog /home/www/logs/discuz-access_log combined |
# 建立Discuz!论坛所需的Rewrite规则
CODE:
<IfModule mod_rewrite.c>
RewriteEngine On RewriteRule ^(.*)/archiver/([a-z0-9\-]+\.html)$ $1/archiver/index.php?$2 RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 RewriteRule ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 </IfModule> </VirtualHost> |
保存并退出文件编辑,下面建立日志存放目录:
CODE:
# mkdir /home/www/logs
|
重新启动Apache:
CODE:
# /usr/local/apache2/bin/apachectl restart
|
至此,一个虚拟主机就建立好了!