Apache配置
1、目录设置,禁止浏览目录 (Options FollowSymLinks )
3、访问量大的限制总并发数和单IP并发
2、访问日志和错误日志每天建个文件
(CustomLog "| /usr/local/apache/bin/rotatelogs /home/logs/www/%Y_%m_%d_access_log 86400 480" common)
4、记录服务器执行时间,方便排查耗时长程序问题。日志格式加上 %D
LogFormat "%D %h %l %u %t \"%r\" %>s %b" common
5、配置HTTPS文件
httpd-ssl.conf文件
Listen 443
<VirtualHost *:443>
ServerName school.xxx.com
DocumentRoot "d:/www"
SSLEngine on
SSLCertificateFile "D:/xxx/apache/conf/ssl.crt/server.crt"
SSLCertificateChainFile "D:/xxxx/apache/conf/ssl.crt/ca-bundle.crt"
SSLCertificateKeyFile "D:/xxxx/apache/conf/ssl.key/server.key"
</VirtualHost>
windows下并发数配置:
<IfModule mpm_winnt_module>
#ThreadLimit 350
ThreadsPerChild 500 // 并发数
MaxRequestsPerChild 10000 // 请求缓存数
Win32DisableAcceptEx
</IfModule>
开启查看实时并发数,吞吐量等信息apache-status
LoadModule status_module modules/mod_status.so
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from all
</Location>
http://192.168.99.99/Server-status?refresh=3 三秒刷新一次
禁止浏览服务器目录, vhost 下也放如下配置
<Directory "D:/www">
Options FollowSymLinks // 即可开启URL跳转,也可以禁止浏览服务器目录AllowOverride All
Require all granted
</Directory>
.Apache Rewrite的配置
Apache下的Rewrite配置主要有两种,一种是针对整个apache服务器的配置,此种配置的Rewrite规则是直接在httpd.conf下书写。配置步骤如下:
(1)去除httpd.conf文件中"#LoadModule rewrite_module modules/mod_rewrite.so"前面的"#"号;
(2)然后再在httpd.conf中书写如下规则:
RewriteEngine on
#当访问任何以t_开头,以.html结尾的文件时,将$1用与(.*)匹配的字符替换后,访问相应的test.php页面
RewriteRule ^/t_(.*).html$ /test.php?id=$1
另一种是针对apache服务器下的某一目录的配置,此种配置的Rewrite规则需在此目录下建立一个.htaccess文件来书写。配置步骤如下:
(1)去除httpd.conf文件中"#LoadModule rewrite_module modules/mod_rewrite.so"前面的"#"号;
(2)修改httpd.conf文件中的"AllowOverride None"为"AllowOverride all",同时最好将Options也置为"FollowSymLinks ",否则可能会出问题。
(3)在目录中建立.htaccess文件,并用记事本打开,书写如下规则:
RewriteEngine on
RewriteRule ^/t_(.*).html$ /test.php?id=$1