Nginx configuration file description

Source: Internet
Author: User
Tags sendfile
A detailed description of the Nginx configuration file, which records the description of the Nginx. conf configuration file of the nginx server, partial annotation collection and network.

# Running user
User www-data;
# Start the process. Generally, it is set to be 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;
}

# Set the http server and use 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, you can set it 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 Request Buffer
Client_header_buffer_size 1 k;
Large_client_header_buffers 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. A higher weight indicates a higher probability of being assigned.
# Enable port 3128 for Squid on the local machine
Server 192.168.8.1: 3128 weight = 5;
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 access logs for the current virtual host
Access_log logs/www.xx.com. access. log main;

# Default request
Location /{
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

Fastcgi_pass www.xx.com;
Fastcgi_param SCRIPT_FILENAME $ document_root/$ fastcgi_script_name;
Include/etc/nginx/fastcgi_params;
}

# Define error prompt page
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/root;
}

# Handle static files by nginx
Location ~ ^/(Images | javascript | js | css | flash | media | static )/{
Root/var/www/virtual/htdocs;
# 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.
Expires 30d;
}
# PHP script requests are all forwarded to FastCGI for processing. Use the default FastCGI configuration.
Location ~ \. Php $ {
Root/root;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/home/www $ fastcgi_script_name;
Include fastcgi_params;
}
# Set the address for viewing Nginx status
Location/NginxStatus {
Stub_status on;
Access_log on;
Auth_basic "NginxStatus ";
Auth_basic_user_file conf/htpasswd;
}
# Prohibit access to the. 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:

# Set the http server and use 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 Server list of Server Load balancer
Upstream mysvr {
# The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned.
Server 192.168.8.1x: 3128 weight = 5; # enable port 3128 for Squid on the local machine
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 requests with the aspx suffix
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 $ proxy_add_x_forwarded_for;
Client_max_body_size 10 m; # maximum number of bytes allowed for client requests per file
Client_body_buffer_size 128 k; # maximum number of bytes for the buffer proxy to buffer client requests,
Proxy_connect_timeout 90; # timeout for nginx connection to backend servers (proxy connection timeout)
Proxy_send_timeout 90; # backend server data return time (proxy sending timeout)
Proxy_read_timeout 90; # response time of the backend server after successful connection (proxy receiving timeout)
Proxy_buffer_size 4 k; # Set the buffer size for the proxy server (nginx) to save user header information
Proxy_buffers 4 32 k; # proxy_buffers buffer, if the average web page is below 32 k, this setting
Proxy_busy_buffers_size 64 k; # buffer size under high load (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 transmitted from the upstream Server

}

}
}

For more information, visit Xiaogang's blog.

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.