Nginx performance optimization settings in CentOS6.3

Source: Internet
Author: User
I. Nginx optimization configuration 1. Master configuration file optimization: # vi/usr/local/nginx/conf/nginx. conf -------------? Usernginxnginx; worker_processes8; worker_cpu_affinity0000000000000000000000000000000000000000000000000; error_l

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 should be that the maximum number of opened files (ulimit-n) is different from the number of nginx processes, however, nginx allocation requests are not so uniform, so it is best to keep them 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 does not exceed 1 k, but generally the system page size is greater than 1 k, set the page size here. You can use the getconf PAGESIZE command to obtain the page size.

Open_file_cache max = 102400 inactive = 20 s;
This will specify the cache for files to be opened. by default, the cache is not enabled. max specifies the number of files to be opened. it is recommended that the cache be deleted when the file is not requested.

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 inactive parameter in the open_file_cache command specifies the minimum number of times files are used. if this number is exceeded, the file descriptor is always opened in the cache. for example, if a file is not used once in the inactive time, it will be removed.


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.