Apache Optimized configuration

Source: Internet
Author: User

1. Configure Static caching

Static file refers to pictures, CSS, JS and other files, the first time after the cache, speed up the access speed

# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Add to the corresponding virtual host

<ifmodule mod_expires.c>

Expiresactive on

Expiresbytype image/gif "Access plus 1 days"

Expiresbytype image/jpeg "Access plus hours"

Expiresbytype image/png "Access plus 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"

</IfModule>

Or use the Mod_headers module to implement

# File cache for Htm,html,txt class one hours

Header set Cache-control "max-age=3600"

# CSS, JS, SWF class file cache for one weeks

Header set Cache-control "max-age=604800"

# jpg,gif,jpeg,png,ico,flv,pdf file cache for one year

header Set Cache-control "max-age=29030400"  


2. Configure the anti-theft chain

Prohibit the white list of websites to take away their own website files, tablets and so on.

# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Setenvifnocase Referer "^http://.*\.yourdomin\.com" Local_ref

Setenvifnocase Referer ". *\.yourdomin\.com" Local_ref

Setenvifnocase Referer "^$" Local_ref

Order Allow,deny

Allow from Env=local_ref

Yourdomin change to whitelist domain name


3. Access control

Let's take a look at the rules for using Allow,deny

Order Deny,allow

Deny from all

Allow from 127.0.0.1

Basis of judgment:

Look at the back of the order, the first one, and then the other. In the example, deny all first, have allow 127.0.0.1, so 127.0.0.1 can be passed


4. Prohibit parsing PHP

In network security, many use this service to prohibit parsing PHP. For example, some directories can upload files, in order to avoid uploading Trojan, so prohibit access to the directory to parse PHP.

Add to the corresponding virtual host

<Directory/data/www/data>

Php_admin_flag engine off  

<filesmatch "(. *) PHP" >

Order Deny,allow

Deny from all

</filesmatch>

</Directory>


5. Prohibit the designation of User_agent

User_agent can be used as a browser logo, the current mainstream has IE, Chrome, Firefox, 360, each browser corresponding to different user_agent.

The configuration for the user_agent limit is as follows

<ifmodule mod_rewrite.c>

Rewriteengine on

Rewritecond%{http_user_agent} ^.*chrome.* [NC]

Rewriterule. *-[F]

</IfModule>

Description

Rewriterule. *-[F] means no access, rewritecond with User_agent to match, ^.*chrome.* said, as long as the user_agent contained chrome is eligible, prohibited. The NC ID is case-insensitive, and an OR OR.


6. Restrict a directory by rewrite

In front of us through deny and allow to restrict the site root directory of a subdirectory or file, in fact, this rewrite module can also be implemented, configured as follows:

<ifmodule mod_rewrite.c>

Rewriteengine on

Rewritecond%{request_uri} ^.*/tmp/* [NC]

Rewriterule. *-[F]

</IfModule>

This setting limits all requests that contain/tmp/.

Like what

www.test.com/tmp/123.php




This article is from the "Liew" blog, make sure to keep this source http://walterliew.blog.51cto.com/11286797/1883748

Apache Optimized configuration

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.