Nginx configuration file nginx.conf details
- 2020-05-12 06:55:07
- OfStack
Record Nginx server nginx.conf's configuration file description here, part of the comments collection with the network.
# Run the user
user www-data;
# Start the process , Usually set to and cpu Is equal to
worker_processes 1;
# 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 It's multiplexing IO(I/O Multiplexing) In the 1 Kind of way , But only for linux2.6 Above the kernel , Can be greatly improved nginx The performance of the
worker_connections 1024;# A single background worker process The maximum number of concurrent links for a process
# multi_accept on;
}
# set http The server, with its reverse proxy function to provide load balancing support
http {
# set mime type , Type by mime.type File defines
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Set log format
access_log /var/log/nginx/access.log;
#sendfile Directive specifies nginx Whether to call sendfile Function ( zero copy To output the file. For normal applications,
# Must be set to on, If used to download applications such as disk IO Heavy duty application, can be set to off To balance disk and network I/O Processing speed, slow down the system uptime.
sendfile on;
#tcp_nopush on;
# Connection timeout
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
# open gzip The compression
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# Set request buffer
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
# Set the list of load balancing servers
upstream mysvr {
#weigth The parameter represents the weight, and the higher the weight, the more likely it is to be assigned
# This machine Squid open 3128 port
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 {
# To listen to 80 port
listen 80;
# Define the use www.xx.com access
server_name www.xx.com;
# Set the access log of the virtual host
access_log logs/www.xx.com.access.log main;
# The default request
location / {
root /root; # Defines the default site root location for the server
index index.php index.html index.htm; # Defines the name of the home page index file
fastcgi_pass www.xx.com;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# Define the error page
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /root;
}
# Static files, nginx Take care of
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /var/www/virtual/htdocs;
# overdue 30 Day, static files do not update, expired can be set to large 1 Click, and if it is updated frequently, it can be set to small 1 Points.
expires 30d;
}
#PHP The script requests all forwards to FastCGI To deal with . use FastCGI The default configuration .
location ~ \.php$ {
root /root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;
include fastcgi_params;
}
# Set the view Nginx Address of status
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
# Blocking access .htxxx file
location ~ /\.ht {
deny all;
}
}
}
These are some basic configurations. The biggest benefit of using Nginx is load balancing
If you want to use load balancing, you can modify the configuration of the http node as follows:
# set http The server, with its reverse proxy function to provide load balancing support
http {
# set mime type , Type by mime.type File defines
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Set log format
access_log /var/log/nginx/access.log;
# Omit the above 1 Some configuration nodes
# .
# Set the list of load balancing servers
upstream mysvr {
#weigth The parameter represents the weight, and the higher the weight, the more likely it is to be assigned
server 192.168.8.1x:3128 weight=5;# This machine Squid open 3128 port
server 192.168.8.2x:80 weight=1;
server 192.168.8.3x:80 weight=6;
}
upstream mysvr2 {
#weigth The parameter represents the weight, and the higher the weight, the more likely it is to be assigned
server 192.168.8.x:80 weight=1;
server 192.168.8.x:80 weight=6;
}
# The first 1 2 virtual servers
server {
# To listen to 192.168.8.x the 80 port
listen 80;
server_name 192.168.8.x;
# right aspx Suffix the load balancing request
location ~ .*\.aspx$ {
root /root; # Defines the default site root location for the server
index index.php index.html index.htm; # Defines the name of the home page index file
proxy_pass http://mysvr ;# The request to mysvr List of defined servers
# The following is a 1 Some reverse proxy configurations can be removed .
proxy_redirect off;
# The back end Web The server can go through X-Forwarded-For Get user real IP
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 10m; # Maximum number of bytes per file allowed for client request
client_body_buffer_size 128k; # The buffer agent buffers the maximum number of bytes requested by the client,
proxy_connect_timeout 90; #nginx The connection timeout with the back-end server ( Proxy connection timeout )
proxy_send_timeout 90; # Backend server data return time ( Agent send timeout )
proxy_read_timeout 90; # Back end server response time after successful connection ( Agent receive timeout )
proxy_buffer_size 4k; # Set up the proxy server ( nginx ) the buffer size to hold the user header information
proxy_buffers 4 32k; #proxy_buffers Buffer the average page in 32k Set this as follows
proxy_busy_buffers_size 64k; # Buffer size under high load ( proxy_buffers*2 )
proxy_temp_file_write_size 64k; # Set the size of the cache folder to be greater than this value and will start from upstream The server transfer
}
}
}