网站服务器Apache的常用配置
工作中用到了Apache服务器-这个世界排名第一的传奇服务器,它功能强大,倍受青睐。作为静态页面首选服务器,那么它具体是怎么用的呢。下面是小编跟大家分享的是网站服务器Apache的常用配置,欢迎大家来阅读学习~
网站服务器Apache的常用配置
方法/步骤
1首先打开Apache安装目录中的conf目录下httpd.conf文件(如D:Apache2.2confhttpd.conf)。
21、配置网站默认发布路径。
默认情况下,Apache的发布路径是安装目录下的htdocs目录,但通常情况我们需要让它指向我们自己的网站目录(如d:/web)。
方法如下:
Ctrl+F查找“DocumentRoot”,
会找到它的默认发布路径:DocumentRoot "D:/Apache2.2/htdocs"。
修改该默认路径为:DocumentRoot "d:/web"即可。

2、让apache支持shtml文件,实现include文件解析。
(1)确认加载include.so模块,将注释去掉。
LoadModule include_module modules/mod_include.so
(2)AddType部分去掉这两段注释:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
(3)目录权限里找到Options Indexes FollowSymLinks,增加Includes
修改为:Options Indexes FollowSymLinks Includes。
(4)重启apache。
测试:



3、添加默认文档index.htm。
查找:DirectoryIndex index.html
替换为:DirectoryIndex index.html index.htm

4、设置404页面。
办法一:
(1)在网站根目录下建立.htaccess文件,新建一个文本,然后用压缩软件压缩此文本,在压缩文件名处输入 .htaccess。
(2)开启.htaccess配置功能:在httpd.conf中设置对目录开启。AllowOverride All
(3)打开.htacccess文件添加以下信息:ErrorDocument 404 /404.html
(4)在网站根目录下新建404.html页面。
办法二:
DocumentRoot "F:wwwabc.com"
ServerName www.abc.com
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride
AllOrder allow,deny
Allow from all
ErrorDocument 404 /404.html

5、禁止目录浏览:
方法一:
将Options Indexes FollowSymLinks修改为Options -Indexes FollowSymLinks。
方法二:
在.htaccess文件中输入
Options -Indexes

6、配置二级域名:
NameVirtualHost *:80(这个必加,否则二级域名访问会跳转到顶级域名)
ServerAdmin administrator
DocumentRoot "d:/web/wapcn"
ServerName wapcn.xxx.com
ServerAdmin administrator
DocumentRoot "d:/web/wapen"
ServerName wapen.xxx.com
ServerAdmin administrator
DocumentRoot "d:/web/weben"
ServerName en.xxx.com
ServerAdmin administrator
DocumentRoot "d:/web/webcn"
ServerName www.xxx.com

7、Apahce解决中文乱码问题:
AddDefaultCharset ISO-8859-1
修改为AddDefaultCharset off
或修改为AddDefaultCharset GB2312
或修改为AddDefaultCharset UTF-8

8、apache加大网站并发量:
ThreadsPerChild 1000
MaxRequestsPerChild 10000
Win32DisableAcceptEx

9、apache加大线程数:
ThreadsPerChild 512
MaxRequestsPerChild 0

10、Apache 按天生成日志
(1)打开httpd.conf配置文件找到: CustomLog "logs/access.log" common
(2)将其改为:CustomLog "|bin/rotatelogs.exe logs/%Y_%m_%d.access.log 86400 480" common
(3)打开httpd.conf配置文件找到: ErrorLog "logs/error.log"
(4)将其改为:ErrorLog "|bin/rotatelogs.exe logs/%Y_%m_%d.error.log 86400 480"


11、开启apache网页监控
删除LoadModule status_module modules/mod_status.so前面的#号。
在httpd.conf中加入:
SetHandler server-status
Order Deny,Allow
Deny from nothing
Allow from all
ExtendedStatus On
访问http://IP:端口/server-status。



网站服务器Apache的常用配置的评论条评论