Apache configuration-domain jump, log cut, static cache, anti-theft chain

Source: Internet
Author: User

/usr/local/apache2/bin/apachectl-m: See which modules are installed
/usr/local/apache2/bin/apachectl-t: Checking for syntax errors

/usr/local/apache2/bin/apachectl-l: Viewing the installed library files

/usr/local/apache2/bin/apachectl Graceful: Reload configuration
/usr/local/apache2/htcocs Home Store Directory

/usr/local/apache2/bin/apachectl Startup file directory

/usr/local/apache2/conf configuration file path
1. Domain Jump  

site can set domain name alias, set the access alias is jump to the primary domain name
· The primary domain name is www.1.com alias Www.a.com,www.b.com. Accessing aliases when jumping to www.1.com
• 301 is a permanent jump, 302 is a temporary jump, there are more than one domain to jump with "OR" to add "or"
in the virtual host configuration file:    

vim  /usr/local/apache/conf/extra/httpd-vhost.conf             <IfModule mod_rewrite.c>          RewriteEngine on                                          rewrite engine  [open]         RewriteCond  %{HTTP_HOST}  ^www.a.com$                   rewrite conditions: when it is www.a.com         rewriterule   ^/(. *) $  www.1.com  /$1  [R=301,L]         rewrite rules: Jump to www.1.com     </ifmodule> 


2. Log polling (cutting)
(1) The log format defined in the Apache master configuration file, the first of which is the complex format , the second is the normal format (working in complex format)

Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined

     logformat "%h%l%u%t \"%r\ "%>s%b" &NBSP; common   
(2) access log format explanation:
         %h: Client's IP address
    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;%L: Client Login name
         %u: Authenticated user
         %t: Date and time of Access
         %r: How customers access, what resources to access, what agreements
         %>s request the corresponding status code (2 starts normally, 3 starts with redirection, 4 starts with a client error, 5 starts on the server side encounters an error)    
         %b: Number of bytes transferred
        % { Referer}: from which page (such as Baidu Search to the QQ space, that Referer is Baidu)
         %{user-agent} : What browser the client uses

(3) Configure log cutting: avoid generating large files, which can generate a daily
· The log format is defined in httpd.conf, and only the log format is called in the virtual host
/usr/local/apache2/conf/httpd.confThe log format is defined in
· Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" Combined
/usr/local/apache2/conf/extra/httpd-vhost.conf Called when log cutting is done with the Rotatelog tool
• Add Customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/apache2/logs/access_%y%m%d.log 86400" to the virtual host configuration file Combined First paragraph: Rotatelog tool path The second paragraph: Log storage path and naming (by month and day name) Third paragraph: Call the log format in httpd.conf to combined format


3. Static caching  

define picture, CSS, JS, SWF expiration time   
· Module used: mod_expires.c 
• In the virtual host configuration file, add:

  vim /usr/local/apache2/conf/extra/http-vhosts.conf               <IfModule  mod_expires.c>       ExpiresActive on                                        expiry date [Open]      expiresbytype image/ gif    "access plus 1 days"         expired type   Visit more than one day         ExpiresByType  text/css    " Access plus 2 hours "      expiresbytype  appliction/ javescripts   "Access plus 2 hours"     </IfModule>


4. Anti-theft chain        
prevent the site's pictures, documents, music and other forms of misappropriation of links, only allowed to specify the domain name can link
• hotlinking: Put a picture on someone else's website, copy the link, Then send on their own website, users to access their site to bear the burden and traffic is someone else's server.  
      template as follows, the defined file format can be added by itself:

    <Directory  /data/www>          SetEnvIfNoCase Referer   "Www.1.com"    local_ref         define the domain name of the access        SetEnvIfNoCase Referer   Www.a.com "   local_ref        define the domain name to be accessed         SetEnvIfNoCase Referer   "Www.b.com"    local_ref         define the domain name to access        setenvifnocase referer    "^$"           local_ref               <filesmatch  "Txt|doc|mps|rar|zip|jpeg|png| Jpg|gif ">    define the format of forbidden Hotlinking               order allow,deny             allow from env= local_ref   set the rules here, allow or disallow            </ Filesmatch>    </directory>

Explanation: The domain name is defined in Setenvifnocase to be able to access the content   the Forbidden hotlinking defined in FilesMatch;
Note: If the domain name other than the domain name defined above is displayed with a 403 error
• Other sites have 403 errors using the hotlinking address, The 401 error is that there is user authentication required to add-u parameter  
5. Disable parsing of PHP in a directory (to prevent the source code from being seen) Span style= "Color:rgb (255,0,0);" > 

 <directory /data/www/uc_server>       php_admin_flag_engine off        Close parsing          <filesmatch  "(. *) PHP" >          file matching is the end of the PHP            Order Deny,Allow             first deny after allow             Deny from all                Reject All          </filesmatch>   </directory> 




Apache configuration-domain jump, log cut, static cache, anti-theft chain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.