Nginx configuration file nginx. conf (summary)

Source: Internet
Author: User
Tags sendfile website performance
PS: I have been using Nginx for two or three years. now I often encounter some basic questions from new users. I have no time to answer them one by one. it took me some time this afternoon, based on your experience, I will share the main configuration parameters of Nginx and some network content. This article is the most...
PS: I have been using Nginx for two or three years. now I often encounter some basic questions from new users. I have no time to answer them one by one. it took me some time this afternoon, based on your experience, I will share the main configuration parameters of Nginx and some network content. this is the most complete Chinese description of Nginx configuration parameters. For more detailed module parameters, see: http://wiki.nginx.org/Main# Define the number of Nginx processes run by the user and user group www; # set to equal to the total number of CPU cores. Worker_processes 8; # global error log definition type, [debug | info | notice | warn | error | crit] error_log ar/logstores/error. log info; # process file pid ar/runner-up. pid; # the maximum number of file descriptors opened by an nginx process. the theoretical value should be the maximum number of opened files (the system value ulimit-n, however, nginx allocation requests are uneven, so we recommend that you keep them consistent with the ulimit-n value. Worker_rlimit_nofile 65535; # working mode and maximum number of connections events {# refer to the event model, use [kqueue | rtsig | epoll |/dev/poll | select | poll]; the epoll model is a high-performance network I/O model in the kernel of Linux 2.6 or later versions. if you are running on FreeBSD, use the kqueue model. Use epoll; # maximum number of connections (maximum number of connections = number of connections * number of processes) worker_connections 65535;} # set http server http {include mime. types; # default_type application/octet-stream; # default file type # charset UTF-8; # server_names_hash_bucket_size 128; # client_header_buffer_size 32 k for the hash table of the server name; # the size of the uploaded file is limited to large_client_header_buffers 4 64 k; # set client_max_body_size 8 m for request slowdown; # set sendfile on; # enable the efficient file transmission mode. the sendfile command specifies whether nginx calls the sendfile function to output files, For general applications that are set to on, if used for downloading and other application disk I/O heavy load applications, you can set it to off to balance the disk and network I/O processing speed and reduce the system load. Note: If the image is not displayed properly, change it to off. Autoindex on; # enable directory list access, which is suitable for downloading servers. it is disabled by default. Tcp_nopush on; # prevent network congestion tcp_nodelay on; # prevent network congestion keepalive_timeout 120; # Long connection timeout time, in seconds # FastCGI-related parameters are used to improve website performance: reduces resource usage and increases 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 gzip on; # enable gzip compression output gzip_min_length 1 k; # minimum compressed file size gzip_buffers 4 16 k; # compressed buffer gzip_http_version 1.0; # compressed version (1.1 by default, use 1.0 for the front-end squid2.5) gzip_comp_level 2; # compression grade gzip_types text/plain application/x-javascript t Ext/css application/xml; # The compression type. textml is already included by default, so you don't need to write it again. there will be no problem if you write it, but there will be a warn. Gzip_vary on; # limit_zone crawler $ binary_remote_addr 10 m; # Use upstream blog.ha97.com {# upstream for load balancing when limiting IP connections. weight is the weight and the weight can be defined based on machine configuration. The weigth parameter indicates the weight. a higher weight indicates a higher probability of being assigned. Server 192.168.80.121: 80 weight = 3; server 192.168.80.122: 80 weight = 2; server 192.168.80.123: 80 weight = 3;} # configure server for the VM {# listen to Port listen 80; # multiple domain names can be separated by spaces: server_name www.ha97.com ha97.com; index index.html index.htm index. php; root/data/www/ha97; location ~. *. (Php | php5 )? $ {Fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; include fastcgi. conf ;}# set the image cache time location ~. *. (Gif | jpg | jpeg | png | bmp | swf) $ {expires 10d;} # JS and CSS cache time settings location ~. *. (Js | css )? $ {Expires 1 h ;} # set the log format to log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request" ''$ status $ response" $ http_referer "'' "$ http_user_agent" $ http_x_forwarded_for '; # define the access log access_log ar/logstores/ha97access for this VM. log access; # enable reverse proxy location/{proxy_pass "/" http://127.0.0.1:88;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 IPproxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; # The following are some reverse proxy configurations, which are optional. Proxy_set_header Host $ host; client_max_body_size 10 m; # maximum number of single-file bytes allowed for client requests client_body_buffer_size 128 k; # maximum number of bytes cached by the buffer proxy client request, proxy_connect_timeout 90; # nginx and backend server connection timeout (proxy connection timeout) proxy_send_timeout 90; # backend server data return time (proxy sending timeout) proxy_read_timeout 90; # After successful connection, response time of the backend server (proxy receiving timeout) proxy_buffer_size 4 k; # set the buffer size proxy_buffers 4 32 k for the proxy server (nginx) to save user header information; # proxy_buffers buffer, set proxy_busy_buffers_size 64 k on average for web pages below 32 k; # buffer under high load Size (proxy_buffers * 2) proxy_temp_file_write_size 64 k; # sets the cache folder size. if it is greater than this value, it will be uploaded from the upstream server} # sets the address location/NginxStatus {stub_status on for viewing Nginx status; access_log on; auth_basic "NginxStatus"; auth_basic_user_file confpasswd; # The content of the htpasswd file can be generated using the htpasswd tool provided by apache .} # Reverse proxy configuration for local dynamic/static separation # All jsp pages are handled 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 $ proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080 ;} # All static files are directly read by nginx without passing through tomcat or resinlocation ~. *. (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 )? For more details about the module parameters, see: http://wiki.nginx.org/Main

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.