nginx configuration

  • 2020-05-06 12:17:29
  • OfStack


# Run the user    
user nobody nobody;   
# Start the process    
worker_processes 2;   
# Global error log and PID The document    
error_log logs/error.log notice;   
pid logs/Nginx.pid;   
# Working mode and connection limit    
events {   
use epoll;   
worker_connections 1024;   
}   
# set http Server, which provides load balancing support with its reverse proxy function    
http {   
# set mime type    
include conf/mime.types;   
default_type application/octet-stream;   
# Set log format    
log_format main '$remote_addr - $remote_user [$time_local] '   
'"$request" $status $bytes_sent '   
'"$http_referer" "$http_user_agent" '   
'"$gzip_ratio"';   
log_format download '$remote_addr - $remote_user [$time_local] '   
'"$request" $status $bytes_sent '   
'"$http_referer" "$http_user_agent" '   
'"$http_range" "$sent_http_content_range"';   
# Set request buffer    
client_header_buffer_size 1k;   
large_client_header_buffers 4 4k;   
# open gzip The module    
gzip on;   
gzip_min_length 1100;   
gzip_buffers 4 8k;   
gzip_types text/plain;   
output_buffers 1 32k;   
postpone_output 1460;   
# set access log   
access_log logs/access.log main;   
client_header_timeout 3m;   
client_body_timeout 3m;   
send_timeout 3m;   
sendfile on;   
tcp_nopush on;   
tcp_nodelay on;   
keepalive_timeout 65;   
# Set the list of load balancing servers    
upstream mysvr {   
#weigth The parameter represents the weight, and the higher the weight, the greater the probability of being 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;   
}   
# Set up virtual host    
server {   
listen 80;   
server_name 192.168.8.1   
www.jb51.net   

charset gb2312;   
# Set the access log of the virtual host    
access_log logs/www.jb51.net.access.log main;   
# If the access  /img/*, /js/*, /css/*  Resource, then directly take the local document, do not pass squid   
# If there are many of these documents, this method is not recommended because it is passed squid Is much better    
location ~ ^/(img|js|css)/ {   
root /data3/Html;   
expires 24h;   
}   
# right  "/"  Enable load balancing    
location / {   
proxy_pass http://mysvr;   
proxy_redirect off;   
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;   
client_body_buffer_size 128k;   
proxy_connect_timeout 90;   
proxy_send_timeout 90;   
proxy_read_timeout 90;   
proxy_buffer_size 4k;   
proxy_buffers 4 32k;   
proxy_busy_buffers_size 64k;   
proxy_temp_file_write_size 64k;   
}   
# Set the view Nginx Address of status    
location /NginxStatus {   
stub_status on;   
access_log on;   
auth_basic "NginxStatus";   
auth_basic_user_file conf/htpasswd;   
}   
}   
} 


Note: the content of the conf/htpasswd document can be generated using the htpasswd tool provided by apache. The content is roughly as follows:
3.) see Nginx running state input address http: / / 192.168.8.1 / NginxStatus /.
Enter the authentication account password and you will see something like
Active connections: 328
server accepts handled requests
9309 8982 28890
Reading: 1 Writing: 3 Waiting: 324

The first line represents the number of connections that are now active, and the third number in the third line represents the number of connections that Nginx has run up to now.

Related articles: