Apache常用配置项
301是永久重定向
302是臨時(shí)重定向
編輯虛擬主機(jī)的配置文件需要用到apache的rewrite模塊
所以要用要先檢查apache是否安裝了rewrite模塊
# ./bin/apachectl -M | grep rewrite
?rewrite_module (shared)
# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
<IfModule mod_rewrite.c>
???? RewriteEngine on
???? RewriteCond %{HTTP_HOST} ^www.aaa.com$ [OR]
???? RewriteCond %{HTTP_HOST} ^www.bbb.com$
???? RewriteRule ^/(.*)$ http://www.fansik.com/$1 [R=301,L]
</IfModule>
Apache日志切割
CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/discuz-access_%Y%m%d_log 86400" combined
Apache不記錄以下結(jié)尾的內(nèi)容
??? SetEnvIf Request_URI ".*\.gif$" image-request
??? SetEnvIf Request_URI ".*\.jpg$" image-request
??? SetEnvIf Request_URI ".*\.png$" image-request
??? SetEnvIf Request_URI ".*\.bmp$" image-request
??? SetEnvIf Request_URI ".*\.swf$" image-request
??? SetEnvIf Request_URI ".*\.js$" image-request
??? SetEnvIf Request_URI ".*\.css$" image-request
CustomLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/discuz-access_%Y%m%d_log 86400" combined env=!image-request
Apache配置靜態(tài)緩存
<IfModule mod_expires.c>
? ExpiresActive on
? ExpiresByType image/gif "access plus 1 days"
? ExpiresByType image/jpeg "access plus 24 hours"
? ExpiresByType image/png "access plus 24 hours"
? ExpiresByType text/css "now plus 2 hours"
? ExpiresByType application/x-javascript "now plus 2 hours"
? ExpiresByType application/x-shockwave-flash "now plus 2 hours"
? ExpiresDefault "now plus 0 min"
</IfModule>
加載好上面的配置后可用curl來(lái)檢查一下哦
# curl -x127.0.0.1:80 'http://120.55.194.217/static/image/common/logo.png' -I
如果出現(xiàn)紅字,說(shuō)明配置成功了,緩存時(shí)間是86400秒
HTTP/1.1 200 OK
Date: Tue, 15 Mar 2016 06:10:29 GMT
Server: Apache/2.4.6 (Unix) PHP/5.6.6
Last-Modified: Tue, 08 Dec 2015 02:39:16 GMT
ETag: "1149-52659e1375d00"
Accept-Ranges: bytes
Content-Length: 4425
Cache-Control: max-age=86400
Expires: Wed, 16 Mar 2016 06:10:29 GMT
Content-Type: image/png
如果沒(méi)效果記得查看一下模塊的開(kāi)關(guān)是不是打開(kāi)了
Apache防盜鏈
SetEnvIfNoCase Referer "^http://.*\.discuz\.com" local_ref
SetEnvIfNoCase Referer ".*\.luntan\.com" local_ref
< filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png|js|css)">
??? Order Allow,Deny
??? Allow from env=local_ref
< /filesmatch>
Apache訪(fǎng)問(wèn)控制(只允許本機(jī)訪(fǎng)問(wèn)admin的管理頁(yè)面admin)
<filesmatch "(.*)admin(.*)">
??????? Order deny,allow
??????? Deny from all
??????? Allow from 127.0.0.1
<filesmatch>
Apache禁止解析某個(gè)目錄下的php文件
<Directory /opt/discuz>
??????? php_admin_flag engine off
??????? <filesmatch "(.*)php">
??????????????? Order deny,allow
??????????????? Deny from all
??????? </filesmatch>
</Directory>
?Apache禁止指定user_agent
<IfModule mod_rewrite.c>
??????? RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]
??????? RewriteCond %{HTTP_USER_AGENT} ^.*chrome* [NC]
??????? RewriteRule .* - [F]
?</IfModule>
Apache限制某個(gè)目錄
<IfModule mod_rewrite.c>
??? RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]
??? RewriteRule .* - [F]
</IfModule>
轉(zhuǎn)載于:https://www.cnblogs.com/fansik/p/5552182.html
總結(jié)
以上是生活随笔為你收集整理的Apache常用配置项的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 这10篇 iOS 热文,你别错过哦
- 下一篇: 如何在3点之前判断基金涨跌 可以参考