Nginx configuration and usage

Source: Internet
Author: User
Tags sendfile
Nginx configuration and use [html] # run user userwww-data; # start the process. Generally, the number of worker_processes1 instances equal to the number of CPUs is set; # global error log and PID file error_log/var/log/nginx/error. log; pid/var/run/ng... nginx configuration and use [html] # run user www-data; # start the process. Generally, the number of worker_processes 1 is equal to the number of CPUs; # global error log and PID file error_log/var/log/nginx/error. log; pid/var/run/nginx. pid; # working mode and maximum number of connections events {use epoll; # epoll is a method in Multiplexing I/O Multiplexing, but it is only used in Linux or later kernels, it can greatly improve nginx performance worke R_connections 1024; # maximum number of concurrent connections of a single backend worker process # multi_accept on;} # set the http server, using its reverse proxy function, server load balancer supports http {# sets the mime type, which is determined by mime. the type file defines include/etc/nginx/mime. types; default_type application/octet-stream; # set the log format access_log/var/log/nginx/access. log; # The sendfile 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 application disk I/O heavy load applications such as downloading, you can set it to off to balance the disk and network I/O processing speed and reduce the system's uptime. sendfile on; # tcp _ Nopush on; # connection timeout # keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; # enable gzip compression gzip on; gzip_disable "MSIE [1-6] \. (?! * SV1) "; # set the request buffer client_header_buffer_size 1 k; large_client_header_buffers 4 4 4 k; include/etc/nginx/conf. d /*. conf; include/etc/nginx/sites-enabled/*; # set the server list of server load balancer upstream mysvr {# The weigth parameter indicates the weight value, the higher the weight, the higher the chance of being allocated to it # enable port 3128 of server 192.168.8.1: 3128 weight = 5 on Squid on the local machine; server 192.168.8.2: 80 weight = 1; server 192.168.8.3: 80 weight = 6;} server {# listen to port 80 listen 80; # define using www.xx.com to access server_name www.xx.com; # set Access log access_log logs/www.xx.com. access. log main; # default request location/{root/root; # define the default website root directory location index of the server. php index.html index.htm; # define the name of the homepage index file fastcgi_pass www.xx.com; fastcgi_param SCRIPT_FILENAME $ document_root/$ fastcgi_script_name; include/etc/nginx/fastcgi_params ;} # define the error prompt page error_page 500 502 503 504/50 x.html; location =/50x.html {root/root;} # handle the static file by nginx ~ ^/(Images | javascript | js | css | flash | media | static)/{root/var/www/virtual/htdocs; # The static file is not updated for 30 days after expiration, you can set the expiration time to a larger value. you can set the expiration time to a smaller value if it is updated frequently. Expires 30d;} # All PHP script requests are forwarded to FastCGI for processing. use FastCGI default configuration. location ~ \. Php $ {root/root; fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME/home/www $ packages; include fastcgi_params;} # set the address location/NginxStatus {stub_status on; access_log on; auth_basic "NginxStatus "; auth_basic_user_file conf/htpasswd;} # access prohibited. htxxx file location ~ /\. Ht {deny all ;}} and above are some basic configurations. The biggest advantage of using Nginx is that if you want to use server load balancer, you can modify the configuration of the http node as follows: [html] # sets the http server and uses its reverse proxy function to provide load balancing support for http {# sets the mime type, which is determined by mime. the type file defines include/etc/nginx/mime. types; default_type application/octet-stream; # set the log format access_log/var/log/nginx/access. log; # omitting some of the preceding configuration nodes #.......... # Set the upstream mysvr {# The weigth parameter in the server list of server load balancer to indicate the weight. the higher the weight, the higher the probability of being allocated to the server 192.168.8.1x: 3128 weight = 5; # enable port 3128 of server 192.168.8.2x: 80 weight = 1; server 192.168.8.3x: 80 weight = 6;} upstream mysvr2 {# The weigth parameter indicates the weight, the higher the weight, the higher the probability of being allocated to the server. the higher the weight, the higher the server 192.168.8.x: 80 weight = 1; server 192.168.8.x: 80 weight = 6 ;} # The first virtual server {# listens to port 80 of 192.168.8.x listen 80; server_name 192.168.8.x; # server load balancer request location ~. * \. Aspx $ {root/root; # define the default website root directory location of the server index. php index.html index.htm; # define the name of the home index file proxy_pass http://mysvr # Redirect requests to the list of servers defined by mysvr # The following are some reverse proxy configurations that can be deleted. proxy_redirect off; # The backend Web server can use X-Forwarded-For to obtain the user's Real IP address proxy_set_header Host $ host; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header X-Forwarded-For $ bytes; 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 For buffer client requests, 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; # proxy_temp_file_write_size 64 k under high load (proxy_buffers * 2) proxy_temp_file_write_size 64 k; # set the cache folder size, greater than this value, after modifying the nginx configuration file from the upstream server: cd/usr/local/nginx/sbin. /nginx-t re-compile nginx. /nginx-s reload restart nginx to reload the new configuration file
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.