Nginx basic configuration and parameter Description Example: nginx basic configuration
# Run user nobody of the user group; # user www;
# Start the process. Generally, worker_processes 1 is set to be equal to the number of CPUs;# Global error log and PID file # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log info;
Events {
# Epoll is a method in Multiplexing I/O Multiplexing. # It is only used in Linux or later kernels and can greatly improve nginx performance.
Use epoll;
# Maximum number of concurrent connections of a single backend worker process
Worker_connections 1024;
# The total number of concurrent jobs is the product of worker_processes and worker_connections.
# Max_clients = worker_processes * worker_connections
# Why max_clients = worker_processes * worker_connections/4 when reverse proxy is set
# Why should the reverse proxy be divided by 4? It should be said that it is an experience value # according to the above conditions, the maximum number of connections that can be handled by the Nginx Server under normal circumstances is: 4*8000 = 32000 # The worker_connections value is determined by the physical memory size.
# Because concurrency is subject to IO constraints, the max_clients value must be smaller than the maximum number of files that can be opened by the System
# The maximum number of files that can be opened by the system is proportional to the memory size. Generally, the number of files that can be opened on machines with 1 GB of memory is about 0.1 million.
# Let's take a look at the number of file handles that can be opened by VPS in MB memory: # $ cat/proc/sys/fs/file-max
# Output 34336 #32000 <34336, that is, the total number of concurrent connections is smaller than the total number of file handles that can be opened by the system, which is within the acceptable range of the operating system.
# Therefore, the worker_connections value must be set based on the number of worker_processes processes and the maximum number of files that can be opened by the system.
# Make the total number of concurrent jobs smaller than the maximum number of files that can be opened by the operating system # The essence is to configure it based on the host's physical CPU and memory
# Of course, in theory, the total number of concurrent jobs may be different from the actual number, because there are other worker processes on the host that consume system resources.
# Ulimit-shn65535
}
http {
# Set the mime type. The type is determined by mime. the type file defines include mime. types; default_type application/octet-stream; # Set the 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/apps/logs/nginx_access.log main; # 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 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]. "; # Set the client_header_buffer_size 128 k for request buffering; large_client_header_buffers 4 128 k; include/apps/conf/nginx/vhosts /*. com; multiple servers are included.
}
server
server { listen 80; server_name goods.api.vipshop.com; index index.html index.php; root /apps/dat/web/working/goods.api.vipshop.com/applications/public; location ^~ /Service { deny all; } location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(html|htm|php)$ { expires 180s; } access_log /apps/logs/nginx/goods_api_access.log log_access;}
server { listen 80; server_name 216.vipshop.com size.vipshop.com 216.vip.vipshop.com 216.vip.com 216.vip.vip.com; index index.html index.htm index.php; root /apps/dat/web/working/216.vipshop.com/web; #error_page 404 = /404.html; error_page 502 /502.html; #limit_conn crawler 20; location ~ .*\.(php|php5|ahtml)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 302400s; } location ~ .*\.(js|css)?$ { expires 302400s; } location ~ .*\.(html|htm|php)$ { expires 180s; } rewrite "^/(show|detail|preview)-([0-9]+)-([0-9]+)-([0-9]+)\.html$" /merchandise.php?act=$1&id=$2&brand_id=$3&goods_sort_id=$4; access_log /apps/logs/nginx/216.access.log log_access; error_log /apps/logs/nginx/216.error.log; }