Detailed description of nginx performance optimization configuration under CentOS6.3 (1/2)

Source: Internet
Author: User
Tags epoll nginx server

I. NGINX optimization configuration

1. Master configuration file optimization:

# Vi/usr/local/nginx/conf/nginx. conf

-----------------------------------------

User nginx;

Worker_processes 8;

Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000;


Error_log/usr/local/nginx/logs/nginx_error.log crit;


Pid/usr/local/nginx/logs/nginx. pid;


Worker_rlimit_nofile 204800;


Events

{

Use epoll;

Worker_connections 204800;

}

 

Http {

Include mime. types;

Default_type application/octet-stream;


Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';


Access_log logs/access. log main;


Charset UTF-8;


Server_names_hash_bucket_size 128;

Client_header_buffer_size 32 k;

Large_client_header_buffers 4 32 k;

Client_max_body_size 20 m;


Sendfile on;

Tcp_nopush on;


Keepalive_timeout 60;


Fastcgi_cache_path/usr/local/nginx/fastcgi_cache levels =

Keys_zone = TEST: 10 m

Inactive = 5 m;

Fastcgi_connect_timeout 300;

Fastcgi_send_timeout 300;

Fastcgi_read_timeout 300;

Fastcgi_buffer_size 64 k;

Fastcgi_buffers 4 64 k;

Fastcgi_busy_buffers_size 128 k;

Fastcgi_temp_file_write_size 128 k;


Open_file_cache max = 204800 inactive = 20 s;

Open_file_cache_min_uses 1;

Open_file_cache_valid 30 s;


Tcp_nodelay on;


Gzip on;

Gzip_min_length 1 k;

Gzip_buffers 4 16 k;

Gzip_http_version 1.0;

Gzip_comp_level 2;

Gzip_types text/plain application/x-javascript text/css application/xml;

Gzip_vary on;

}

-----------------------------------------


Note: Some configuration details:

Worker_processes 8;

The number of nginx processes. We recommend that you specify the number of CPUs, which is generally a multiple of them.


Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000

10000000;

Allocate cpu to each process. In the previous example, eight processes are allocated to eight CPUs. Of course, you can write multiple processes or allocate one process to multiple CPUs.

.


Worker_rlimit_nofile 204800;

This command indicates the maximum number of file descriptors opened by an nginx process. The theoretical value is the maximum number of opened files (ulimit-n

) Is different from the number of nginx processes, but the nginx allocation request is not so even, so it is best to be consistent with the ulimit-n value.

Note: ulimit-SHn 204800 needs to be set here


Use epoll;

Use the I/O model of epoll.


Worker_connections 204800;

The maximum number of connections allowed by each process. Theoretically, the maximum number of connections per nginx server is

Worker_processes * worker_connections.


Keepalive_timeout 60;

Keepalive timeout.


Client_header_buffer_size 4 k;

The buffer size of the client request header, which can be set based on the size of your system page. Generally, the size of the header of a request is not

More than 1 k, but generally the system page size is greater than 1 k, so here set to the page size. Run the getconf command to display the page size.

Get PAGESIZE.


Open_file_cache max = 102400 inactive = 20 s;

This will specify the cache for the opened files, which is not enabled by default. max specifies the cache quantity. It is recommended that the cache be consistent with the number of opened files, inactive

It refers to the time after which files are not requested to delete the cache.


Open_file_cache_valid 30 s;

This refers to how long it takes to check the cache's valid information.


Open_file_cache_min_uses 1;

The minimum number of times the file is used in the inactive parameter time in the open_file_cache command. If this number is exceeded, file descriptor 1

Directly opened in the cache. In the preceding example, if a file is not used once in the inactive time, it will be removed.

Homepage 1 2 Last page

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.