Apache相关配置记录

防盗链,主要根据访问来源 HTTP_REFERER 来判断是否来源本站,如果不是则返回设定的图片:
<VirtualHost 106.888.888.88:80>
    ServerAdmin [email protected]
    DocumentRoot "/opt/app/php/xxxxx.img"
    ServerName img.xxxxx.com
    ServerAlias img.xxxxx.com
    ErrorLog "logs/img.xxxxx.com-error.log"
    CustomLog "/etc/httpd/logs/img.xxxxx.com.access.log" combined
    DirectoryIndex index.php index.html  index.htm
    <Directory "/opt/app/php/xxxxx.img">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    <Directory "/opt/app/php/xxxxx.img">
      <FilesMatch ".(php|asp|jsp)$">
        Deny from all
      </FilesMatch>
    </Directory>
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://xxxxx.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://xxxxx.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.xxxxx.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.xxxxx.com$ [NC]
    RewriteRule .*\.(gif|jpg|png|swf)$ http://www.xxxxx.com/nolink.jpg [R,NC]
</VirtualHost>

301重定向,老域名转向新域名,保持域名权重:

<VirtualHost 192.168.1.12:80>  
    ServerAdmin [email protected]  
    ServerName toooom.com  
    ServerAlias www.toooom.com  
    RedirectMatch Permanent ^/(.*) http://www.haolianduo.com/$1  
</VirtualHost>



安全配置,目录禁止执行php,exe,jsp等程序文件:
<VirtualHost 106.xxx.xx.xx:80>
    ServerAdmin [email protected]
    DocumentRoot "/opt/app/php/xxxxx.info"
    ServerName info.xxxxx.com
    ServerAlias info.xxxxx.com
    ErrorLog "logs/info.xxxxx.com-error.log"
    CustomLog "/etc/httpd/logs/info.xxxxx.com.access.log" combined
    DirectoryIndex index.php index.html  index.htm
    <Directory "/opt/app/php/xxxxx.info">
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    <Directory "/opt/app/php/xxxxx.info/uploads">
      <FilesMatch ".(php|asp|jsp)$">
        Deny from all
      </FilesMatch>
    </Directory>
    <Directory "/opt/app/php/xxxxx.info/data">
      <FilesMatch ".(php|asp|jsp)$">
        Deny from all
      </FilesMatch>
    </Directory>
</VirtualHost>





你可能感兴趣的:(apache,重定向,防盗链,目录安全)