Optimizing Nginx server configuration in CentOS (1/3)

Source: Internet
Author: User
Tags fpm centos nginx server

Nginx is a mainstream and powerful reverse proxy WEB server. Since moving to Tencent cloud server, Nginx has been used as the WEB server on this site. Next we will talk about some of the Nginx optimizations:
The specific process of compiling and installing Nginx is not mentioned here. The following is my Nginx installation directory tree:
[Root @ VM_40_253_centos nginx] # tree ./
./
── Client_body_temp
── Conf
│ ── Fastcgi. conf
│ ── Fastcgi. conf. default
│ ── Fastcgi_params
│ ── Fastcgi_params.default
│ ── Koi-utf
│ ── Koi-win
│ ── Mime. types
│ ── Mime. types. default
│ ── Nginx. conf
│ ── Nginx. conf. default
│ ── Optimization. conf
│ ── Scgi_params
│ ── Scgi_params.default
│ ── Uwsgi_params
│ ── Uwsgi_params.default
│ ── Win-utf
├ ── Fastcgi_temp
── Html
│ ── 50x.html
│ ── Index.html
│ ├ ── Tz. php
│ ── Tz.zip
── Logs
│ ── Access_2014-06-09.log.
│ ── Access. log
│ ── Error. log
│ ── Newaccess. log
│ ── Nginx. pid
── Proxy_temp
── Sbin
│ ── Cut-log.sh.
│ ── Nginx
── Scgi_temp
── Uwsgi_temp
── Vhosts
── Demo.iloxp.com. conf
── Iloxp. conf
── Kutea. conf
── Kutea. conf. bak
── Kutea. conf. old

Optimization points:

1. Of course, wildcard domain name resolution is disabled. Enable default host --> point to 403. Enable virtual host --> point to your own website;
2. Enable gzip compression to reduce server bandwidth output and improve access speed;
3. Enable cache;
4. Access control: disable unnecessary access logging, such as requests from favicon. ico;
5. Log management, of course, is cut. Access logs are recorded by date to facilitate analysis;
6. Optimize the default connections of php-fpm and nginx to reduce the number of errors by 502, and reload your php-fpm process on a regular basis.
OK. Write so much first. The specific optimization process is not mentioned here. Google's gperftools are a huge number on the internet. By the way, Google's gperftools are useless for independent nginx servers and small memory.

Example

1. Master configuration file optimization:

The code is as follows: Copy code

# 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;
}
-----------------------------------------

Homepage 1 2 3 Last page
Related Article

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.