Nginx configuration file full version (using the latest stable version of NGINX1.8.0)

Source: Internet
Author: User
Tags epoll sendfile

# Users and groups to use
User Nginx Nginx;

# Specify the number of work-derived processes; typically several cores are configured with several CPUs. The number of nginx processes, the recommended setting is equal to the total CPU core number.
Worker_processes 1;

#全局错误日志及PID文件; Global error log definition type, [Debug | info | notice | warn | error | crit]
Error_log/var/log/nginx/error.log warn;
#进程文件
Pid/var/run/nginx.pid;

#一个nginx进程打开的最多文件描述符数目, the theoretical value should be the number of open files (the value of the system ulimit-n) and the number of nginx processes, but the Nginx allocation request is not uniform, so the recommendation is consistent with the value of ulimit-n.
#worker_rlimit_nofile 65535;

#工作模式与连接数上限
Events {
#参考事件模型, use [kqueue | rtsig | epoll |/dev/poll | select | poll]; Epoll model,
#是Linux the high-performance network I/O model in kernel 2.6 or higher, if running on FreeBSD, use the Kqueue model.
#具体内容查看 http://wiki.codemongers.com/Event Model
Use Epoll;

#单个进程最大连接数(最大连接数=连接数*进程数)connections 2000worker_connections  1024;

}
#设定http服务器
http {
#文件扩展名与文件类型映射表, set MIME type, type defined by Mime.type file
Include/etc/nginx/mime.types;

#默认文件类型default_type application/octet-stream; #默认编码 #charset utf-8; #反向代理配置, you can open proxy.conf and see #include/etc/nginx/.  proxy.conf; #fastcgi配置, you can open fastcgi.conf to see #include/etc/nginx/fastcgi.conf;  #日志的格式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/var/log/nginx/access.lo g Main; #sendfile directive Specifies whether Nginx calls the Sendfile function (zero copy mode) to output files, for normal applications, #必须设为 on, if used for downloading applications such as disk IO heavy-duty applications, can be set to off to balance disk and network i/ o processing speed, reduce system uptime.sendfile on, #开启目录列表访问, appropriate download server, default off. #autoindex on; #防止网络阻塞 #tcp_nopush on; #连接超时时间, units are seconds keepalive_timeout; #防止网络阻塞tcp_nodelay on; #服务器名字的hash表大小 #serv Er_names_hash_bucket_size, #上传文件大小限制 #client_header_buffer_size 32k, #设定请求缓 #large_client_header_buffers 4 64k;# Set request cache #client_max_body_size 8m; #FastCGI相关参数是为了改善网站的性能: Reduce resource usage and improve access speed. The following parameters can be understood by literal means. #fastcgi_connect_timeout, #fastcgi_send_timeout, #fastcgi_read_timeoUT #fastcgi_buffer_size 64k; #fastcgi_buffers 4 64k; #fastcgi_busy_buffers_size 128k; #fastcgi_temp_file_write_ Size 128k; #gzip模块设置 # Open gzip compression output #gzip on; #最小压缩文件大小 #gzip_min_length 1k; #压缩缓冲区 #gzip_buffers 4 16k;# Compressed version (default 1.1, front End If it is squid2.5 Use 1.0) #gzip_http_version 1.0; #压缩等级 #gzip_comp_level 2; #压缩类型, the default is text/html, so there's no need to write anymore. It won't be a problem to write, but there will be a warn. #gzip_types text/plain application/x-javascript text/css application/xml; #gzip_vary on; #开启限制IP连接数的时候需要使用 #limit_zone Crawler $binary _remote_addr 10m;include/etc/nginx/conf.d/*.conf; #include/etc/nginx/sites-enabled/*; #设定负载均衡的服务器列表 #upstream Ctrip_oa_tomcat {# #upstream的负载均衡, weight is the weight that can be defined based on machine configuration. The Weigth parameter represents weights, and the higher the weight, the greater the probability of being allocated. # server 127.0.0.1:8080 weight=1;# server 192.168.1.116:8081 weight=1;#} #设定负载均衡的服务器列表, you can configure multiple server lists for load Balancing #upstream Ctri P_OA_TOMCAT2 {# #upstream的负载均衡, weight is a weight that can be defined based on machine configuration. The Weigth parameter represents weights, and the higher the weight, the greater the probability of being allocated.    # server 127.0.0.1:8080 weight=1;# server 192.168.1.116:8081 weight=1;#} #虚拟主机的配置server {#监听端口 listen 80; #域名可以There are multiple, separated by spaces server_name 192.168.1.116;    #定义首页 index index.html index.htm index.jsp;    #文件根目录 Root/home/oa/ctripoa-ui/usky-ctripoa-uui/public;    #定义错误页面 error_page 400 402 403 404 405 406 410 411 413 416 500 501 502 503 504 /error.html;    Error_page 505/error.html; #日志格式设定 #log_format access ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent "$http    _referer "' # '" $http _user_agent "$http _x_forwarded_for ';    #定义本虚拟主机的访问日志 #access_log/var/log/nginx/ctrip_oa_access.log access; #默认访问地址

Location/{
Expires 2m;
Add_header Cache-control "Public, must-revalidate, proxy-revalidate";
Add_header Cache-control "Public, must-revalidate, proxy-revalidate";
}

#所有的rest请求都是以api开头的
Location ~/sms/(api|images|files)/{
Proxy_pass http://localhost:8080;
Proxy_next_upstream error timeout;
Proxy_connect_timeout 8s;

Proxy_intercept_errors on;
Proxy_set_header X-forwarded-host hTT p H osT;PRox y s e t H ead eRX ?F oRWaRd ed ?S eRveR Host
Proxy_set_header x-forwarded-for proxy_add_x_forwarded_for;
Proxy_set_header X-real-ip REMOTE_ADDR;
Proxy_set_header Host $http _host;
}
#默认请求
#对 "/" Enable reverse Proxy
#location/{
#proxy_pass localhost;

        #proxy_redirect off;        #proxy_set_header X-real-ip $remote _addr;        #后端的Web服务器可以通过X-forwarded-for Obtain the user real IP #proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;        #以下是一些反向代理的配置, optional.        #proxy_set_header Host $host;        #允许客户端请求的最大单文件字节数 #client_max_body_size 10m;        #缓冲区代理缓冲用户端请求的最大字节数, #client_body_buffer_size 128;         #nginx跟后端服务器连接超时时间 (proxy connection timeout) #proxy_connect_timeout 90;        #后端服务器数据回传时间 (proxy send timeout) #proxy_send_timeout 90;        #连接成功后, back-end server response time (proxy receive timeout) #proxy_read_timeout 90;        #设置代理服务器 (Nginx) Save the user header information buffer size #proxy_buffer_size 4k;        #proxy_buffers缓冲区, the average Web page is set below 32k #proxy_buffers 4 32k;        #高负荷下缓冲大小 (proxy_buffers*2) #proxy_busy_buffers_size 64k;        #设定缓存文件夹大小, greater than this value, will be transmitted from the upstream server #proxy_temp_file_write_size 64k;     #} #以下为静态资源, Nginx handle #静态文件, Nginx handle #location ~ ^/(images|javascript|js|css|flash|media|static)/{# root/hOme/oa/ctripoa-ui/usky-ctripoa-uui;  # expires 30d;    #过期30天, the static files are not updated, the expiration can be set a little larger, if updated frequently, you can set a smaller point. #} #图片缓存时间设置 #location ~. *.    (gif|jpg|jpeg|png|bmp|swf) $ {# expires 30d; #} #JS和CSS缓存时间设置 #location ~. *.    (JS|CSS)? $ {# expires 30h; #} #所有jsp的页面均交由tomcat或resin处理 #location ~.    (JSP|JSPX|DO)? $ {# Proxy_set_header Host $host;    # Proxy_set_header X-real-ip $remote _addr;    # Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;    # Proxy_pass http://127.0.0.1:8080; #} #所有静态文件由nginx直接读取不经过tomcat或rest #location ~. *.    (htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma) $ {# expires 15d; #} #location ~. *.     (JS|CSS)? $ {# expires 1h;    #} #设定查看Nginx状态的地址 #location/nginxstatus {#stub_status on;    #access_log on;    #auth_basic "Nginxstatus";    #auth_basic_user_file conf/htpasswd;    #htpasswd文件的内容可以用apache提供的htpasswd工具来产生. #}

}
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nginx configuration file full version (using the latest stable version of NGINX1.8.0)

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.