1、vim /usr/local/apache2/conf/httpd.conf
删除#Include conf/extra/httpd-vhosts.conf 前面的#号
2、vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 虚拟主机配置文件
加入如下配置:
DocumentRoot "/data/www" (站点文件存放位置)
ServerName
下面介绍几种常用虚拟主机的配置:
1、虚拟主机配置用户认证
AllowOverride AuthConfig
AuthName "自定义的"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
/usr/loacle/apapche2/bin/htpasswd -cm /data/.htpasswd liuye
重启apache 服务,访问站点,效果如下:
2、配置域名跳转
RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^/(.*)$ $1 [R=301,L]
测试输入 自动跳转到
3、配置apache访问日志
ErrorLog "|/usr/local/apache/bin/rotatelogs -l /usr/local/apache/logs/oem.discuz.qq.com-error_%Y%m%d.log 86400"
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/oem.discuz.qq.com-access_%Y%m%d.log 86400"
combined env=!image-request
4、配置静态文件缓存
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 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
5、配置防盗链
SetEnvIfNoCase Referer "^*\.yourdomin\.com" local_ref
SetEnvIfNoCase Referer ".*\.yourdomin\.com" local_ref
SetEnvIfNoCase Referer "^$" local_ref
Order Allow,Deny
Allow from env=local_ref
6、配置访问控制
#访问控制
Order deny,allow
Deny from all
Allow from 192.168.1.107
只允许192.168.1.107主机进行访问
阅读(2654) | 评论(0) | 转发(0) |