The security optimization of the Linux Nginx

Source: Internet
Author: User

we said the last verse. Apache of the Web service security and optimization. Separately said process optimization, version number of the hidden, session connection time,DNS query. We just have to master these optimization points is enough, we do not blindly pursue refinement, what has a degree, you get too much, the corresponding other aspects will also die, so we optimize the standard is to find a compromise point, is the best! Next we say nginx Web Services Security optimization.

Nginx Principle of safety optimization and Apache roughly the same, there are some subtle differences, and change the parameters of the place is different!

in said optimization Nginx before we first understand his structure: 650) this.width=650; "src=" Http://img.baidu.com/hi/ldw/w_0021.gif "alt=" W_0021.gif "/>

Nginx composed of cores and modules, where the kernel is designed to be very small and concise, the work done is very simple, simply by locating the configuration file to map the client request to a location block (the location is a directive in the Nginx configuration for URL matching), Each instruction that is configured in this location will start a different module to do the work accordingly.

Nginx modules are structurally divided into core modules, base modules and third-party modules. :

Core Modules : HTTP Module, event module, and Mail module

Basic Modules : HTTP access module, HTTP fastcgi module, HTTP proxy module, and HTTP rewrite module,

third-party modules : http Upstream Request Hash module, notice module, and HTTP Access key module.

650) this.width=650; "src=" Http://img.baidu.com/hi/ldw/w_0012.gif "alt=" W_0012.gif "/>

One profile optimization

1. Hidden Nginx of the Header Version number information Server_tokensoff;

650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M01/7D/75/ Wkiol1bpabadpnmraaaspvny1ck977.png "title=" qq picture 20160316113655.png "alt=" Wkiol1bpabadpnmraaaspvny1ck977.png "/> 650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7D/77/wKiom1bo_5vzMNaMAAAqT-9qxBE125.png "title=" QQ picture 20160316113802.png "alt=" wkiom1bo_5vzmnamaaaqt-9qxbe125.png "/>2 .< Span style= "font-size:9px;font-family: ' Times New Roman ';" >     change nginx

Nginx The default user is Nobody, when compiling, change to Nginx. (Note: This step was made when we compiled the installation.)

3. Configuration Nginx of the worker Number of processes

this starts with CPU number for reference, followed by business settings.

worker_processes 5; Modify this

4. according to CPU optimization of the number of cores Nginx Process

worker_cpu_affinity0001 0010 0100; This is quad-core . CPU Optimized

5. Nginx event-handling model optimization

Events {

Worker_connections 1024;

Use Epoll;

}

6. Adjustment Nginx single process allows maximum number of clients to connect

worker_connections 20480; It's not too small.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7D/77/wKiom1bo_-zgYnzEAACzKpiV3MY754.png "title=" QQ picture 20160316133222.png "alt=" Wkiom1bo_-zgynzeaaczkpiv3my754.png "/>

7. Set the connection time-out period

Keepalive_timeout 60;

8. Configure nginx gzip compression function 650) this.width=650; "Src=" http://img.baidu.com/hi/ldw/w_0039. GIF "alt=" w_0039.gif "/>

Configuration Nginx gzip compression function ### Optimization Focus ###

HTTP {

Server_tokens off;

gzip on;

Gzip_min_length 1k;

Gzip_http_version 1.1;

Gzip_buffers 4 32k;

Gzip_comp_level 9;

Gzip_types application/javascript text/css Text/xml;

Gzip_vary on;

Note: Gzip_types The corresponding file type is in the installation directory Mime.type file

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7D/77/wKiom1bpACbAZMwFAAA7rTkPrko080.png "title=" QQ picture 20160316140509.png "alt=" Wkiom1bpacbazmwfaaa7rtkprko080.png "/>

Configure Nginx expires cache function 650) this.width=650; "Src=" Http://img.baidu.com/hi/ldw/w_ 0022.gif "alt=" W_0022.gif "/>

Cache Expires Optimized

Expirse refers to how long the file is stored on the client when the customer visits the website. This is what the server decides, and that's what he realizes.

in the Nginx the configuration is placed in Location in

Expires 30d;

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7D/75/wKioL1bpANnC710LAAA4n25-bhw363.png "title=" QQ picture 20160316140724.png "alt=" Wkiol1bpannc710laaa4n25-bhw363.png "/>

Nginx optimization We grasp the above can be, in production, we can according to their actual needs to configure the parameters of each optimization point. Isn't it very simple ah! Children's shoes we must believe in ourselves, if you do not believe in yourself, you will find him very difficult! It's not hard to believe in yourself! No, no! 650) this.width=650; "src=" Http://img.baidu.com/hi/ldw/w_0014.gif "alt=" w_0014.gif "/>


This article from "Lele Run" blog, please be sure to keep this source http://10851431.blog.51cto.com/10841431/1751757

The security optimization of the Linux Nginx

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.