Nginx 1.10.1 version nginx.conf optimized configuration and detailed comments

Source: Internet
Author: User
Tags sendfile

#普通配置

#== Performance Configuration



#运行用户

User nobody;

#pid文件

PID Logs/nginx.pid;

The number of #==worker processes, usually set equal to the number of CPUs, auto is automatically detected

Worker_processes Auto;

#==worker process Open Maximum number of files, can cpu*10000 set

Worker_rlimit_nofile 100000;

#全局错误日志

Error_log Logs/error.log;



#events模块中包含nginx中所有处理连接的设置

Events {

#==worker the maximum number of connections that the process can open at the same time, cpu*2048 settings

Worker_connections 2048;

#== tells Nginx to accept as many links as possible after receiving a new link notification

Multi_accept on;

#== setting the rotation method for reusing client threads

Use Epoll;

}



#http模块控制着nginx all core features of HTTP processing

HTTP {

#打开或关闭错误页面中的nginx版本号deng

Server_tokens on;

#!server_tag on;

#!server_info on;

#== optimize the disk IO settings, specify whether Nginx calls the Sendfile function to output the file, the normal application is set to ON, download and other high-disk IO applications, can be set to off

Sendfile on;

#== set Nginx to send all header files in one packet, not one after the other

Tcp_nopush on;

#== set Nginx do not cache data, but a paragraph of the Send,

#== when you need to send data in a timely manner, you should set this property to the app so that you don't get the return value immediately when you send a small piece of data.

Tcp_nodelay on;


#== set Nginx whether to store access logs, close this can make read disk IO operation faster

Access_log on;

#设置nginx只记录严重错误

#error_log Logs/error.log Crit;


#== assigning keep-alive link time-outs to clients

Keepalive_timeout 30;


#设置用户保存各种key的共享内存的参数, 5m means 5 trillion.

Limit_conn_zone $binary _remote_addr zone=addr:5m;

#为给定的key设置最大的连接数, here the key is addr, set the value is 100, that is, allow each IP address to open up to 100 connections at a time

Limit_conn addr 100;


#include指在当前文件中包含另一个文件内容

Include Mime.types;

#设置文件使用默认的mine-type

Default_type text/html;

#设置默认字符集

CharSet UTF-8;


#== set Nginx to send data in the form of gzip compression, reducing the amount of data sent, but will increase the request processing time and CPU processing time, need to weigh

gzip on;

#== plus vary to the proxy server, for some browsers support compression, there is an unsupported, based on the client's HTTP header to determine whether compression is required

Gzip_vary on;

#nginx在压缩资源之前, find out if there are pre-gzip-processed resources

#!gzip_static on;

#为指定的客户端禁用gzip功能

Gzip_disable "msie[1-6]\.";

#允许或禁止压缩基于请求和相应的响应流, any represents the compression of all requests

Gzip_proxied any;

#== sets the minimum number of bytes to enable compression on the data, and does not compress if the request is less than 10240 bytes, which can affect the request speed

Gzip_min_length 10240;

#== set data compression level, 1-9, 9 slowest compression ratio maximum

Gzip_comp_level 2;

#设置需要压缩的数据格式

Gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml Application/xml+rss;


#== Development Cache also specifies the maximum number of cache files, 20s delete the cache if the file is not requested

Open_file_cache max=100000 inactive=20s;

#== refers to how long it takes to check the cache for valid information

Open_file_cache_valid 60s;

#== File cache minimum number of accesses, which are cached only if accessed more than 5 times

Open_file_cache_min_uses 5;

#当搜索一个文件时是否缓存错误信息

Open_file_cache_errors on;


#== maximum number of single-file bytes allowed for client requests

Client_max_body_size 8m;

#== The maximum number of bytes that the client request is buffered by a flush zone agent

Client_header_buffer_size 32k;


#

Proxy_redirect off;

#后端的Web服务器可以通过X-forwarded-for Get the user real IP

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

#==nginx with back-end server connection time-out (proxy connection timed out)

Proxy_connect_timeout 60;

#== back-end server response time (proxy receive timeout) after successful connection

Proxy_read_timeout 120;

#== back-end server data backhaul time (proxy send timeout)

Proxy_send_timeout 20;

#== Setting the proxy server (nginx) buffer size for saving user header information

Proxy_buffer_size 32k;

#==proxy_buffers buffer, the average Web page is set below 32k

Proxy_buffers 4 128k;

#== buffer size under high load (proxy_buffers*2)

Proxy_busy_buffers_size 256k;

#== Set cache folder size, greater than this value, will be transmitted from the upstream server

Proxy_temp_file_write_size 256k;

#==1g Memory buffer space, 3 days without deletion, maximum disk buffer space 2G

Proxy_cache_path/home/cache levels=1:2 keys_zone=cache_one:1024m inactive=3d max_size=2g;



#设定负载均衡服务器列表

Upstream nginx.test.com{

#后端服务器访问规则

#ip_hash;

#weight参数表示权重值, the higher the weight, the greater the chance of being assigned.

#server 10.11.12.116:80 weight=5;

#PC_Local

Server 10.11.12.116:80;

#PC_Server

Server 10.11.12.112:80;

#Notebook

#server 10.11.12.106:80;

}


#虚拟主机设定模块 (Mount multiple sites, you only need to configure multiple servers and upstream nodes)

server {

#监听80端口

Listen 80;

#定义使用nginx. test.com Access

server_name nginx.test.com;

#设定本虚拟主机的访问日志

Access_log Logs/nginx.test.com.access.log;

#默认请求

# syntax rule: location [=|~|~*|^~]/uri/{...} first matches normal location, matches regular location

# = start with exact match

# ^~ begins with a URI that begins with a regular string and is understood to match the URL path, regardless of the codec

# ~ Start to indicate case-sensitive regular matches

# ~* Start indicates case-insensitive regular match

#!~ starts with a case-sensitive mismatch

#!~* Start indicates a case-insensitive mismatch

#/Generic match, any request will be matched to

Location/{

#定义服务器的默认网站根目录位置

root HTML;

#定义首页索引文件的名称

Index index.html index.htm;

#定义后端负载服务器组

Proxy_pass http://nginx.test.com;

}


#定义错误提示页面

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

#静态文件, Nginx handles it himself.

Location ~ ^/(images|javascript|js|css|flash|media|static)/{

Root/var/www/virtual/htdocs;

#过期时间1天

Expires 1d;

#关闭媒体文件日志

Access_log off;

Log_not_found off;

}

#设定查看Nginx状态的地址

Location/nginxstatus {

#!stub_status on; #无此关键字

Access_log off;

Auth_basic "Nginxstatus";

Auth_basic_user_file conf/htpasswd;

}

#禁止访问的文件. htxxx

Location ~/\.ht {

Deny all;

}

}

#网站较多的情况下ngxin又不会请求瓶颈可以考虑挂多个站点, and put the virtual host configuration in a single file, introduced in

#include website.conf;

}


This article is from the "Ops Little Boss" blog, please be sure to keep this source http://solin.blog.51cto.com/11319413/1884136

Nginx 1.10.1 version nginx.conf optimized configuration and detailed comments

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.