Nginx server nginxconf configuration file description

Source: Internet
Author: User
Tags sendfile
: This article describes the Nginx server nginxconf configuration file. if you are interested in the PHP Tutorial, refer to it. Record the description of the Nginx. conf configuration file on the nginx server, partial annotation collection and network.

Running user

User www-data;

Start the process, usually set to equal to the number of CPUs

Worker_processes 1;

Global error logs and PID files

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 of Multiplexing IO (I/O Multiplexing), but it is only used for Linux and later kernels, which can greatly improve nginx performance.
Worker_connections 1024; # maximum number of concurrent connections of a single backend worker process
# Multi_accept on;
}

Sets the http server and uses its reverse proxy function to provide load balancing support

Http {
# Set the mime type, which is defined by the mime. type file.
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 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; # 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 {
# Listening to port 80
Listen 80;
# Define access using www.xx.com
Server_name www.xx.com;

# Set the 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 ;}}

}

The above are some basic configurations. The biggest advantage of using Nginx is load balancing.

To use server load balancer, you can modify and configure the http node as follows:

Sets the http server and uses its reverse proxy function to provide load balancing support

Http {
# Set the mime type, which is defined by the mime. type file.
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
# Set the log format
Access_log/var/log/nginx/access. log;

# Omit some of the above 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. a higher weight indicates a higher probability of being assigned.

server 192.168.8.x:80  weight=1;server 192.168.8.x:80  weight=6;}

# First Virtual Server
Server {
# Listen to port 80 of 192.168.8.x
Listen 80;
Server_name 192.168.8.x;

# Load balancing request location ~ for aspx suffix ~ . *\. Aspx $ {root/root; # define the default website root directory Location index of the server. php index.html index.htm; # define the name of the home index file proxy_pass http: // mysvr; # Request to the server list 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, will be uploaded from upstream server }}

}

The above describes the Nginx server nginxconf configuration file, including the content, and hope to be helpful to friends who are interested in PHP tutorials.

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.