您的位置:首页 > 运维架构 > Apache

apache web服务器常用配置

2017-01-07 20:07 435 查看
lamp基础上搭建DiscuzX3.2论坛,通过配置/path/to/apache/conf/extra/httpd-vhosts.conf,实现以下功能。

httpd-vhosts.conf配置内容如下:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
#
#默认主机
<VirtualHost *:80>
DocumentRoot "/tmp/111"
ServerName 11.com
</VirtualHost>

#Discuz虚拟主机配置
<VirtualHost *:80>
DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.test2.com

#设置用户访问权限
<Directory /data/www/auth>
AllowOverride AuthConfig
AuthName "Please enter the username and password!"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>

#访问控制
<Directory /data/www>
AllowOverride None
Options None
Order allow,deny
Allow from all
Deny from 192.168.1.100
</Directory>

<FilesMatch "(.*)admin(.*)">
Order deny,allow
Deny from all
Allow from 192.168.1.99 192.168.1.103
</FilesMatch>

#禁止/ /目录php文件解析
<Directory /data/www/data>
php_admin_flag engine off
<filesmatch "(.*)php">
Order deny,allow
Deny from all
</filesmatch>
</Directory>

#设置访问日志不记录image请求
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

#错误日志和日志分割
ErrorLog "logs/test.com-error_log"
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_log_%Y%m%d 86400" combined env=!image-request

#301跳转_rewrite和禁止user_agent访问
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.test2.com$
RewriteRule ^/(.*)$ http://www.test.com/$1 [L,R=301]

#RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]
#RewriteCond %{HTTP_USER_AGENT} ^.*chrome.* [NC]
#RewriteRule .* - [F]

RewriteCond %{REQUEST_URI} ^.*/tmp/.* [NC]
RewriteRule .* - [F]
</IfModule>

#配置防盗链
SetEnvIfNoCase Referer "^http://.*\.test\.com" local_ref   #白名单url
<FilesMatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)">
Order Allow,Deny
Allow from env=local_ref
</FilesMatch>

#配置浏览器缓存_expires
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 1 days"
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>

</VirtualHost>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apache web服务器 lamp