百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

nginx 代理设置一 之常见的设置(nginx代理http2)

off999 2025-02-03 14:31 15 浏览 0 评论

1、nginx代理配置 proxy_pass

server {
	listener 8099;

 location = /test {
		proxy_pass http://192.168.18.132:9010;
	} 
}

2、nginx 代理中设置请求头 proxy_set_header

server {
	listener 8099;
	
 	location = /test {
			proxy_pass http://192.168.18.132:9010;
  		# 设置请求头
  		proxy_set_header Host $proxy_host;
	} 
}

3、nginx 反向代理中设置请求超时时间 proxy_send_timeout

server {
	listener 8099;
  
 	location = /test {
			proxy_pass http://192.168.18.132:9010;
  		# 设置请求头
  		proxy_set_header Host $proxy_host;
  		# 设置请求超时时间  默认是60s
      proxy_send_timeout 30s;
	} 
}

4、nginx反向代理中设置 请求响应超时时间 proxy_read_timeout

server {
listener 8099;
  			
 location = /test {
			proxy_pass http://192.168.18.132:9010;
  		# 设置请求头
  		proxy_set_header Host $proxy_host;
  		# 设置请求超时时间  默认是60s
      proxy_send_timeout 30s;
  		# 设置请求响应超时时间 默认是60s
  		proxy_read_timeout 10s;
	} 
}

5、nginx反向代理中设置 允许的响应头 proxy_pass_header 和 需要隐藏的响应头 proxy_hide_header

server {
listener 8099;
  			
 location = /test {
		proxy_pass http://192.168.18.132:9010;
  
  	# 设置请求头
  	proxy_set_header Host $proxy_host;
  
  	# 设置请求超时时间  默认是60s
    proxy_send_timeout 30s;
  
  	# 设置请求响应超时时间 默认是60s
  	proxy_read_timeout 10s;
  	
  	proxy_pass_header xxxx;  # 放行
    proxy_hide_header abc;   # 隐藏
	} 
}

6、重新设置cookie的path proxy_cookie_path

server {
listener 8099;
  
 location = /test {
	 proxy_pass http://192.168.18.132:9010;
  
   # 设置请求头
   proxy_set_header Host $proxy_host;
  
   # 设置请求超时时间  默认是60s
   proxy_send_timeout 30s;
  
   # 设置请求响应超时时间 默认是60s
   proxy_read_timeout 10s;
   
   proxy_pass_header xxxx;  # 放行
   proxy_hide_header abc;   # 隐藏
              
   proxy_cookie_path /user/ /;  #意味着 path=/user/some/uri/ 改成 path=/some/uri/
	} 
}

7、设置cookie 的属性 proxy_cookie_flags(1.19.3以上版本才有)

server {
	listener 8099;
  			
 	location = /test {
			proxy_pass http://192.168.18.132:9010;
  
  		# 设置请求头
  		proxy_set_header Host $proxy_host;
  
  		# 设置请求超时时间  默认是60s
      proxy_send_timeout 30s;
  
  		# 设置请求响应超时时间 默认是60s
  		proxy_read_timeout 10s;
  		
  		proxy_pass_header xxxx;  # 放行
      proxy_hide_header abc;   # 隐藏
      
      proxy_cookie_path /user/ /; #意味着 path=/user/some/uri/ 改成 path=/some/uri/
      
        # 设置cookie属性相关举例 如ecure, httponly, samesite=strict, samesite=lax, samesite=none
  			# 相反 nosecure, nohttponly, nosamesite 表示去掉相关属性
       proxy_cookie_flags username secure; # 意味着 给username这个cookie增加secure 属性
       proxy_cookie_flags ~ nosecure samesite=strict; # 意味着 删除secure属性,增加samesite=strict属性
		} 
}

8、设置DNS服务 resolver resolver_timeout

server {
	listener 8099;
  			
 	location = /test {
  		# 设置代理DNS解析
  		resolver 127.0.0.1 [::1]:5353;
  		resolver_timeout 10s; #默认30s
      # xxx.com.cn ===> 192.168.18.132
			proxy_pass http://xxx.com.cn:9010;

  		# 设置请求头
  		proxy_set_header Host $proxy_host;

  		# 设置请求超时时间  默认是60s
      proxy_send_timeout 30s;
  		
     # 设置请求响应超时时间 默认是60s
  		proxy_read_timeout 10s;
  		
  		proxy_pass_header xxxx;  # 放行
      proxy_hide_header abc;   # 隐藏
      
      proxy_cookie_path /user/ /; #意味着 path=/user/some/uri/ 改成 path=/some/uri/
       
        # 设置cookie属性相关举例 如ecure, httponly, samesite=strict, samesite=lax, samesite=none
  			# 相反 nosecure, nohttponly, nosamesite 表示去掉相关属性
       proxy_cookie_flags username secure; # 意味着 给username这个cookie增加secure 属性
       proxy_cookie_flags ~ nosecure samesite=strict; # 意味着 删除secure属性,增加samesite=strict属性
		} 
}

9、设置读取客户端数据超时时间(指前后两次读取的时间间隔) client_body_timeout

server {
	listener 8099;
  			
 	location = /test {
  	# 设置代理DNS解析
  	resolver 127.0.0.1 [::1]:5353;
  	resolver_timeout 10s; #默认30s
    # xxx.com.cn ===> 192.168.18.132
		proxy_pass http://xxx.com.cn:9010;

  	# 默认60s, 意味着前后两次读取的时间超过10s(不是指全部读取时间)就返回 408 (Request Time-out)错误 
  	client_body_timeout 10s; 
  } 
}

10、设置客户端的最大请求体 client_max_body_size

server {
	listener 8099;
  			
	location = /test {
  		# 设置代理DNS解析
  		resolver 127.0.0.1 [::1]:5353;
  		resolver_timeout 10s; #默认30s
      # xxx.com.cn ===> 192.168.18.132
			proxy_pass http://xxx.com.cn:9010;
  		# 默认60s, 意味着前后两次读取的时间超过10s(不是指全部读取时间)就返回 408 (Request Time-out)错误 
  		client_body_timeout 10s; 
  		client_header_timeout 10s; #读取【全部】请求头的超时时间,超过则报 408 (Request Time-out)错误 
  	
      # 设置客户端最大请求体
			client_max_body_size 512k; #默认1M,超过则报 413 (Request Entity Too Large) error
      .......
     } 
}

相关推荐

咱村里有个老爷子,居然自学起了Python编程

咱村里有个老爷子,没什么文化,居然自学起了Python编程,还搞出个“智能喂鸡系统”,这事儿可把整个村子都惊到了。要说这老爷子,平时就爱琢磨些新鲜玩意儿。一开始,大家还以为他是瞎折腾,毕竟都一把年纪了...

真上头!清华打造的最全Python教程,通俗易懂,学不会我退出IT圈

前言随着人工智能的发展,Python近两年也是大火,越来越多的人加入到Python学习大军,对于毫无基础的人该如何入门Python呢?小编这里整理了一套python编程零基础自学教程,清华大佬196小...

如何学好Python技术(怎么才能学会python)

现在python发展势头很猛,都想快速学好它,其实学任何一个语言没有太多好的秘诀,一般情况下,还是少不了你努力刻苦的样子。学好一门技术并不容易,很多人推荐学习python,在于比其他语言的约束,或者...

如何高效且系统地自学Python?(自己学python怎么学)

关于这个问题,我也算有些话语权吧!5年多经验的我,今天和大家分享一套系统性学习Python的方法,几周内系统性地学会Python并不是啥难事!首先,学习Python确立明确的学习目标至关重要。要系统性...

使用 Python 监控文件系统(基于python的监控系统)

前言在我们使用服务器的时候,有时候需要监控文件或文件夹的变化。例如,定期扫描文件夹下是否有某一类型的文件生成。今天,我们介绍如何使用Python来监控文件系统。在Python中,主要有两个监控...

Python文件读写最佳实践:关键操作的异常处理

在Python中进行文件操作时,合理的异常处理是保证程序健壮性的关键。以下是针对文件操作异常处理的全面指南。一、为什么需要异常处理?文件操作可能失败的常见原因:文件不存在(FileNotFoundEr...

Python编程笔记(python编程入门与案例详解)

1.Python简介Python是一种解释型、高级和通用的编程语言。它通过显著的缩进使用来强调代码的可读性。#HelloWorldprogramprint("Hello,World...

Python目录与文件操作教程(python word目录)

大家好,我是ICodeWR。今天要记录的是如何使用Python进行常见的目录和文件操作。Python提供了强大的内置模块来处理文件和目录操作。1.基本模块介绍Python中主要使用以下模块进行文件...

自动创建 Python 的 requirements.txt 文件

技术背景在Python开发中,requirements.txt文件用于记录项目所依赖的第三方库及其版本,方便在不同环境中部署项目。然而,当从GitHub下载Python源代码时,有时会缺...

Python文件操作指南(python 操作文件)

一、核心函数open()精解基本语法open(file,mode='r',encoding=None,errors=None,newline=None)关键参数解析1.f...

Python 实现从文本文件提取数据并分析保存

一、引言在日常的数据处理工作中,我们经常会遇到从文本文件中提取特定信息并进行分析的需求。本文将详细介绍如何使用Python编写代码,从一个包含用户网络使用信息的文本文件中提取用户姓名、入站流量和出...

22-3-Python高级特性-上下文管理器

4-上下文管理器4-1-概念上下文管理器是一种实现了`__enter__()`和`__exit__()`方法的对象;用于管理资源的生命周期,如文件的打开和关闭、数据库连接的建立和断开等。使用...

python:最简单爬虫之使用Scrapy框架爬取小说

python爬虫框架中,最简单的就是Scrapy框架。执行几个命令就能生成爬虫所需的项目文件,我们只需要在对应文件中调整代码,就能实现整套的爬虫功能。以下在开发工具PyCharm中用简单的Demo项目...

Python爬取小说技术指南(python爬取文章)

在Python中爬取小说需要遵循法律法规和网站的服务条款,请确保你有权获取目标内容。以下是使用Python爬取小说的通用技术流程安装依赖库pipinstallrequestsbeauti...

python原始套接字socket下载http网页文件到txt

python原始套接字socket下载http网页文件到txtimportsocketdefdownload_webpage(url,output_file):try:...

取消回复欢迎 发表评论: