多语言展示
当前在线:412今日阅读:175今日分享:29

网站服务器Apache的常用配置【实战经验】

工作中用到了Apache服务器-这个世界排名第一的传奇服务器,它功能强大,倍受青睐。作为静态页面首选服务器,那么它具体是怎么用的呢。下面我来说说它的常用配置:
方法/步骤
1

首先打开Apache安装目录中的conf目录下httpd.conf文件(如D:\Apache2.2\conf\httpd.conf)。

2

1、配置网站默认发布路径。默认情况下,Apache的发布路径是安装目录下的htdocs目录,但通常情况我们需要让它指向我们自己的网站目录(如d:/web)。方法如下:Ctrl+F查找“DocumentRoot”,会找到它的默认发布路径:DocumentRoot 'D:/Apache2.2/htdocs'。修改该默认路径为:DocumentRoot 'd:/web'即可。

3

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

4

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

5

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

6

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

7

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

8

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

9

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

10

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

11

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'

12

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

推荐信息