nginx common configuration explained

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/QWERTY1994/article/details/88907023

Under this configuration file to configure the three sites

1.\work  127.0.0.1:8181\hp

2. \ is 127.0.0.1:9091\es

3.\          127.0.0.1:9191\

 


#user  nobody;
#  参考:https://blog.csdn.net/qq_33730348/article/details/80481962
# 工作进程:一般设置等于小于CPU的核心数 如果不知道怎么配置 可以配置为auto 
#worker_processes  auto;
worker_processes  1;
# 进程的最大打开文件数
worker_rlimit_nofile 65535;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#pid        logs/nginx.pid;



events {
	# 调整Nginx单个进程允许客户端的最大连接数
	# (假如是nginx直接返回数据到浏览器,那么就最大连接数是worker_connections*worker_processes)
	# (假如是反向代理的话还要除以2,因为有一半的连接是nginx和服务器的连接)
    worker_connections  4096;
	#设定Nginx的工作模式 通常不需要明确指定它,因为nginx默认使用最有效的方法。
	#use		icop;
	#最大可用客户数;
	#maxClient	2000;
	# 防止惊群效应
	accept_mutex	on;
	# 开启进程同时接收多个请求
	multi_accept	on;
}


http {

    include       mime.types;
    default_type  application/octet-stream;
	#日志格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_x_forwarded_for"';
	# 访问日志
    access_log  logs/access.log  main;

	# 开启高效文件传输
    sendfile        on;
	# 数据包不会马上发出去,等待一定大小在一次发出,有助于解决网络堵塞
	tcp_nopush		on;
    # 马上发送数据
	# tcp_nodelay		on;
   
	
	#设置可通过一个保持活动连接提供的最大请求数。在发出最大请求数后,将关闭连接。
	#	keepalive_requests number;
    #keepalive_timeout  0;
	#用于设置客户端连接保持会话的超时时间为60秒。超过这个时间,服务器会关闭该连接
    keepalive_timeout  65;
	#限制用户通过某一请求向服务端发送请求的次数
	keepalive_requests 70;
	#开启压缩
    gzip  on;
	#从header头中获取的主机名
	proxy_set_header Host $host;
	#获取header头中获取的主机的真实IP
	proxy_set_header X-Real-IP $remote_addr;
	#后端服务器可以从X-Forwarded头中获取用户的真实ip 
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_connect_timeout 90s; #Nginx跟后端服务器连接超时时间(代理连接超时)
    proxy_send_timeout 90s;#后端服务器数据回传时间(代理发送超时)
    proxy_read_timeout 120s;#连接成功后,后端服务器响应时间(代理接收超时)
	proxy_buffer_size	4k;#设置代理服务器nginx保存用户头信息的缓冲区大小
	proxy_buffers	4	32k;#proxy_buffers缓冲区,网页平均在32k以下的设置
	proxy_busy_buffers_size	64k;#高负荷下缓冲大小(proxy_buffers*2)
	proxy_temp_file_write_size	64k;#设定缓冲文件夹大小,大于这个值,就会发出
	
	
	# 上传文件大小限制
	client_max_body_size 100m;
	#设置读取客户端请求头数据的超时时间 如果超过这个时间,客户端还没有发送完整的header数据,服务端将数据返回“Request time out (408)”错误
	client_header_timeout 30;
	# 设置读取客户端请求主体的超时时间。这个超时仅仅为两次成功的读取操作之间的一个超时,
	# 非请求整个主体数据的超时时间,如果在这个超时时间内,客户端没有发送任何数据,Nginx将返回“Request time out(408)”错误,默认值是60.
	client_body_timeout 30;
	#指定响应客户端的超时时间。这个超时时间仅限于两个链接活动之间的事件,如果超过这个时间,客户端没有任何活动,Nginx将会关闭连接,默认值为60s,可以改为参考值25s
	send_timeout 30;
	#设置用于请求主体的缓冲区大小
	client_body_buffer_size		128k;
	
	server {
        listen       80;
        server_name  localhost;
		charset		utf-8;

        #charset koi8-r;

		# 匹配/woker请求
		location = /woker/ { 
			proxy_pass   http://127.0.0.1:8181;
        } 
		# 匹配woker站点.do 和jsp 结尾的请求
        location ~ ^/woker/.*\.(do|jsp)$ { 
			proxy_pass   http://127.0.0.1:8181;
        }
        location ~ ^/woker/.*{ 
			# 对应的woker站点的目录上一级
			root E:/IDEA_SOURCE/worker/target/;
			expires 30d; 
        } 
		
		# 匹配另一站点首页
		location = / { 
			proxy_pass   http://127.0.0.1:9191;
        }
		location = /market { 
			proxy_pass   http://127.0.0.1:9191;
        }		
		
		# 静态资源文件下载
		location ~ ^/(upload|resources|images)/.* {
			# /对应的目录的上一级目录
			root E:/webapp/app/;
			expires 30d; 
		}
		location = /favicon.ico {
			# /对应的目录的上一级目录
			root E:/webapp/app/;
			expires 30d; 
		}
		# 匹配/站点jsp和do结尾请求
		location ~ ^/.*\.(jsp|do|html)$ { 
			proxy_pass   http://127.0.0.1:9191;
        } 
		
		# 匹配es站点
		location /es/ { 
			proxy_pass   http://localhost:9091;
        } 
		
		# nginx状态查看配置
		location /NginxStatus{
			stub_status		on;
			
			allow			127.0.0.1;
			#auth_basic		"NginxStatus";
			#auth_basic_user_file	confpasswd.conf;	
		}
		
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        } 
    }
}

Some reverse proxy configuration in detail: 

proxy_connect_timeout 90s; # 代表上图中 2 的时间

 

Guess you like

Origin blog.csdn.net/QWERTY1994/article/details/88907023