Nginx configuration file full version (use the latest stable version NGINX1.8.0), nginxnginxnginx1.8.0

Source: Internet
Author: User
Tags epoll sendfile website performance

Nginx configuration file full version (use the latest stable version NGINX1.8.0), nginxnginxnginx1.8.0

# Used users and groups
User nginx;

# Specify the number of work-derivative processes. Generally, several CPU cores are configured. Number of nginx processes. We recommend that you set it to equal to the total number of CPU cores.
Worker_processes 1;

# Global error log and PID file; Global error Log definition type, [debug | info | notice | warn | error | crit]
Error_log/var/log/nginx/error. log warn;
# Process files
Pid/var/run/nginx. pid;

# The maximum number of file descriptors opened by an nginx process. The theoretical value should be that the maximum number of opened files (system value ulimit-n) is the same as the number of nginx processes, but the allocation requests of nginx are uneven, therefore, we recommend that you keep the value consistent with that of ulimit-n.
# Worker_rlimit_nofile 65535;

# Maximum number of working modes and connections
Events {
# Refer to the event model. use [kqueue | rtsig | epoll |/dev/poll | select | poll]; epoll model,
# It is a high-performance network I/O model in the kernel of Linux 2.6 or later versions. If it runs on FreeBSD, it uses the kqueue model.
# For details, see http://wiki.codemongers.com/event Model
Use epoll;

# Maximum number of connections of a single process (maximum number of connections = number of connections * Number of processes) connections 2000worker_connections 1024;

}
# Set the http server
Http {
# File extension and file type ing table, set the mime type, the type is defined by the mime. type file
Include/etc/nginx/mime. types;

# Default file type default_type application/octet-stream; # default encoding # charset UTF-8; # reverse proxy configuration, which can be enabled. conf to see # include/etc/nginx/proxy. conf; # fastcgi configuration. You can enable fastcgi. conf to see # include/etc/nginx/fastcgi. conf; # log format log_format main' $ remote_addr-$ remote_user [$ time_local] "$ request" ''$ status $ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for" '; # access log access_log/var/log/nginx/access. log main; # sen The dfile command specifies whether nginx calls the sendfile function (zero copy mode) to output files. For common applications, # It must be set to on. If it is used for downloading and other application disk I/O heavy load applications, it can be set to off to balance the disk and network I/O processing speed and reduce the system uptime. sendfile on; # enable directory list access, which is suitable for downloading servers. This function is disabled by default. # Autoindex on; # preventing network congestion # tcp_nopush on; # connection timeout time, in seconds: keepalive_timeout 65; # preventing network congestion tcp_nodelay on; # server name hash table size # server_names_hash_bucket_size 128; # size limit of uploaded files # client_header_buffer_size 32 k; # Set Request delay # limit 4 64 k; # Set Request cache # client_max_body_size 8 m; # FastCGI parameters are used to improve website performance: reduce resource usage and increase access speed. The following parameters can be understood literally. # Fastcgi_connect_timeout 300; # fastcgi_send_timeout 300; # fastcgi_read_timeout 300; # fastcgi_buffer_size 64 k; # fastcgi_buffers 4 64 k; # limit 128 k; # limit 128 k; # gzip module setting # enable gzip compression output # gzip on; # minimum compressed file size # gzip_min_length 1 k; # compressed buffer # gzip_buffers 4 16 k; # compressed version (default 1.1, for the front end squid2.5, use 1.0) # gzip_http_version 1.0; # compression level # gzip_comp_level 2; # The compression type. By default, text/html is included, so you do not need to write it again, no questions will be asked if it is written. But there will be a warn. # Gzip_types text/plain application/x-javascript text/css application/xml; # gzip_vary on; # Use # limit_zone crawler $ binary_remote_addr 10 m to enable IP connection restriction; include/etc/nginx/conf. d /*. conf; # include/etc/nginx/sites-enabled/*; # Set the Server list of Server Load balancer # upstream ctrip_oa_tomcat {## upstream load balancing, weight is the weight, you can define the weight based on the machine configuration. The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned. # Server 127.0.0.1: 8080 weight = 1; # server 192.168.1.116: 8081 weight = 1 ;#}# set the server list of server Load balancer, you can configure a list of servers for multiple Server Load balancer instances # upstream ctrip_oa_tomcat2 {## upstream Server Load balancer. weight is the weight. You can define the weight according to the machine configuration. The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned. # Server 127.0.0.1: 8080 weight = 1; # server 192.168.1.116: 8081 weight = 1 ;#}# configure server {# listen to port listen 80; # multiple domain names, use spaces to separate server_name 192.168.1.116; # define the homepage index index.html index.htm index. jsp; # root/home/oa/ctripoa-ui/usky-ctripoa-uui/public; # define the error page 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 setting # log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request" '#' $ status $ body_bytes_sent "$ http_referer" '#' "$ http_user_agent" $ http_x_forwarded_for '; # define the access log of the VM # access_log/var/log/nginx/ctrip_oa_access.log access; # default access address

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

# All rest requests start with an api
Location ~ /Sms/(api | images | files )/{
Proxy_pass http: // localhost: 8080;
Proxy_next_upstream error timeout;
Proxy_connect_timeout 8 s;

Proxy_intercept_errors on;
Proxy_set_header X-Forwarded-Host Httphost; proxysetheaderX −forwarded −server Host;
Proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for;
Proxy_set_header X-Real-IPremote_addr;
Proxy_set_header Host $ http_host;
}
# Default request
# Enable reverse proxy "/"
# Location /{
# Proxy_pass localhost;

# Proxy_redirect off; # proxy_set_header X-Real-IP $ remote_addr; # the backend Web server can use X-Forwarded-For to obtain the user's Real IP address # proxy_set_header X-Forwarded-For $ response; # The following are some reverse proxy configurations, which are optional. # Proxy_set_header Host $ host; # maximum number of single-file bytes allowed for client requests # client_max_body_size 10 m; # maximum number of bytes for buffer client requests, # client_body_buffer_size 128; # nginx and backend server connection timeout (proxy connection timeout) # proxy_connect_timeout 90; # backend server data return time (proxy sending timeout) # proxy_send_timeout 90; # after successful connection, response time of the backend server (proxy receiving timeout) # proxy_read_timeout 90; # Set the buffer size for the proxy server (nginx) to save user header information # proxy_buffer_size 4 k; # proxy_buffers buffer, set the average webpage size below 32 KB # proxy_buffers 4 32 KB; # buffer size under high load (proxy_buff Ers * 2) # proxy_busy_buffers_size 64 k; # Set the cache folder size. If it is greater than this value, it will be uploaded from the upstream server # proxy_temp_file_write_size 64 k; #}# The following is a static resource, nginx self-processing # static files, nginx self-processing # location ~ ^/(Images | javascript | js | css | flash | media | static)/{# root/home/oa/ctripoa-ui/usky-ctripoa-uui; # expires 30d; # static files are not updated for 30 days after they expire. You can set them to a larger value when they expire. If they are updated frequently, you can set them to a smaller value. #}# Image Cache Time Setting # location ~. *. (Gif | jpg | jpeg | png | bmp | swf) $ {# expires 30d ;#}# JS and CSS cache time settings # location ~. *. (Js | css )? $ {# Expires 30 h; #}# all jsp pages are processed by tomcat or resin # location ~. (Jsp | jspx | do )? $ {# Proxy_set_header Host $ host; # proxy_set_header X-Real-IP $ remote_addr; # proxy_set_header X-Forwarded-For $ scheme; # proxy_pass http: // 127.0.0.1: 8080; #}# all static files are directly read by nginx without passing through tomcat or 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 1 h ;#}# set the address for viewing Nginx status # location/NginxStatus {# stub_status on; # access_log on; # auth_basic "NginxStatus "; # auth_basic_user_file conf/htpasswd; # the content of the htpasswd file can be generated using the htpasswd tool provided by apache. #}

}
}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.