1024programmer Nginx Detailed interpretation of Nginx configuration file content

Detailed interpretation of Nginx configuration file content

Here, record the configuration file description of the Nginx server nginx.conf, some comments collection and network.

#running user
user www-data;
#Start the process, usually set to be equal to the number of cpu
worker_processes 1;

#Global error log and PID file
error_log /var/log/nginx/error.log;
pid
/var/run/nginx.pid;

#Working mode and connection limit
events {
use
epoll;
#epoll is multiplexed IO(I/O
Multiplexing), but only for kernels above linux2.6, can greatly improve the performance of nginx
Worker_connections 1024; #Single background worker
The maximum number of concurrent connections of the process
# multi_accept on;
}

#Set up the http server, 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 log format
access_log
/var/log/nginx/access.log;

The #sendfile directive specifies whether nginx calls the sendfile function (zero
copy method) to output files, for common applications,
#Must be set to on, if it is used for downloading and other applications with heavy loads of disk IO, it can be set to
off, to balance disk and network I/O processing speed and reduce system uptime.
sendfile on;
#tcp_nopush on;

#Connection timeout
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#Open gzip 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 load balancing server list
upstream mysvr {
The #weigth parameter represents the weight value, the higher the weight value, the greater the probability of being assigned
#Squid on this machine opens port 3128
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 {
#Listen on port 80
listen 80;
#Definition Use www.xx.com to access
server_name
www.xx.com;

#Set the access log of this virtual host
access_log
logs/www.xx.com.access.log main;

#default request
location / {
root /root;
#Define the server’s default website root directory location
index
index.php index.html index.htm; #Define 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 error prompt page
error_page 500 502 503 504
/50x.html;
Location = /50x.html
{
root
/root;
}

#Static files, nginx handles by itself
location ~
^/(images|Javascript|js|css|flash|media|static)/ {
root
/var/www/virtual/htdocs;
#Expired for 30 days, static files are not updated very much, the expiration can be set larger, if it is updated frequently, it can be set smaller.
expires 30d;
}
#PHP script requests are all forwarded to FastCGI for processing. Use the default configuration of FastCGI.
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 address to view the status of Nginx
location /NginxStatus {
stub_status
on;
access_log
on;
auth_basic
“NginxStatus”;
auth_basic_user_file conf/htpasswd;
}
#Prohibit access to .htxxx files
location ~ /\.ht {
deny all;
}
}
}

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

If you want to use load balancing, you can modify the configuration 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 log format
access_log
/var/log/nginx/access.log;

#Omit some configuration nodes above

#. . . . . . . . . .

#Set load balancing server list
upstream mysvr {
The #weigth parameter represents the weight value, the higher the weight value, the greater the probability of being assigned
server 192.168.8.1x:3128
weight=5;#Squid on this machine opens port 3128
server 192.168.8.2x:80 weight=1;
server 192.168.8.3x:80 weight=6;
}

upstream mysvr2 {
The #weigth parameter represents the weight value, the higher the weight value, the greater the probability of being assigned

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

#The first virtual server
server {
#Listen to port 80 of 192.168.8.x
listen 80;
server_name
192.168.8.x;

#Load balancing request for aspx suffix
location ~ .*\.aspx$ {

root root /root;
#Define the server’s default website root directory location
index
index.php index.html index.htm; #Define the name of the home page 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 back-end web server can obtain the user’s real IP through X-Forwarded-For
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; #The maximum number of bytes for a single file requested by the client
client_body_buffer_size 128k; #The buffer agent buffers the maximum number of bytes requested by the client,
proxy_connect_timeout 90; #nginx and backend server connection timeout (proxy connection timeout)
proxy_send_timeout 90;
#Backend server data return time (agent sending timeout)
proxy_read_timeout
90;
#After the connection is successful, the response time of the backend server (agent receiving timeout)
proxy_buffer_size
4k;
#Set the buffer size of the proxy server (nginx) to save user header information
proxy_buffers 4
32k;
#proxy_buffers buffer, if the average web page is below 32k, set it like this
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, if it is greater than this value, it will be uploaded from the upstream server

}

}
}

nbsp;
#The back-end web server can obtain the user’s real IP through X-Forwarded-For
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; #The maximum number of bytes for a single file requested by the client
client_body_buffer_size 128k; #The buffer agent buffers the maximum number of bytes requested by the client,
proxy_connect_timeout 90; #nginx and backend server connection timeout (proxy connection timeout)
proxy_send_timeout 90;
#Backend server data return time (agent sending timeout)
proxy_read_timeout
90;
#After the connection is successful, the response time of the backend server (agent receiving timeout)
proxy_buffer_size
4k;
#Set the buffer size of the proxy server (nginx) to save user header information
proxy_buffers 4
32k;
#proxy_buffers buffer, if the average web page is below 32k, set it like this
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, if it is greater than this value, it will be uploaded from the upstream server

}

}
}

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/detailed-interpretation-of-nginx-configuration-file-content/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索