nginx 代理N个服务,通过URL上下文区分,其中一个服务是登录服务,写cookie.
api服务:http:/www.domain.com/api
SSO服务:http://www.domain.com/sso
前端服务:http://www.domain.com/front
登录成功后,sso服务写cookie:
Set-Cookie:
SESSION=YmUyMDMwMGItZjc1ZC00ZmE1LWIwNmQtYTljMTczNWFhNDE3; Path=/sso/; HttpOnly; SameSite=Lax
前端服务提交请求时,在/front不能使用/sso下的cookie,所以造成登录无效。
所以需要/sso 服务,写cookie时,把 cooke的 Path=/sso/ 改为==》 Path=/; /front才能使用该 cookie .
实现方式 nginx
location /sso{
proxy_pass http://sso proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host; proxy_set_header
Connection keep-alive; proxy_set_header Keep-Alive 600;
keepalive_timeout 600;
proxy_cookie_path /sso/ /;
}
Syntax: proxy_cookie_path off; proxy_cookie_path path replacement; Default: proxy_cookie_path off; Context: http, server, location This directive appeared in version 1.1.15. Sets a text that should be changed in the path attribute of the “Set-Cookie” header fields of a proxied server response. Suppose a proxied server returned the “Set-Cookie” header field with the attribute “path=/two/some/uri/”. The directive proxy_cookie_path /two/ /; will rewrite this attribute to “path=/some/uri/”. The path and replacement strings can contain variables: proxy_cookie_path $uri /some$uri; The directive can also be specified using regular expressions. In this case, path should either start from the “~” symbol for a case-sensitive matching, or from the “~*” symbols for case-insensitive matching. The regular expression can contain named and positional captures, and replacement can reference them: proxy_cookie_path ~*^/user/([^/]+) /u/$1; There could be several proxy_cookie_path directives: proxy_cookie_path /one/ /; proxy_cookie_path / /two/; The off parameter cancels the effect of all proxy_cookie_path directives on the current level: proxy_cookie_path off; proxy_cookie_path /two/ /; proxy_cookie_path ~*^/user/([^/]+) /u/$1;
相关推荐
nginx sticky是nginx的module,可以实现基于cookie的负载均衡。 下载后,在编译安装nginx时,用--add-module... ./configure --prefix=/usr/local/nginx-1.6.0 --add-module=../nginx-sticky-module-1.25 --without-...
在windows 7 64位 环境下使用nginx的nginx-http-flv-module搭建flv视频流播放所有的安装包,参考:https://blog.csdn.net/qq_33071429/article/details/102628008
1、最新版 nginx-http-flv-module(windows可执行程序,含nginx 1.19.3,http-flv-module:1.2.7) 2、内含说明文档,请下载查看。 3、请勿放置于中文路径下,否则无法启动
windows平台nginx编译nginx-http-flv-module,可直接运行,基于nginx-1.17.10编译
--> nginx-1.21.6 ======================== 在网上查找半天都只有教程,没有可免费下载的版本,深知没有积分遍地找资源的痛苦,无奈之下只好自己按照教程一步一个坑编译出来的,供大家免费下载使用。(无毒放心使用...
1、最新版 nginx-http-flv-module(linux可执行程序,含nginx 1.19.3,http-flv-module:1.2.7) 2、内含说明文档,请下载查看。 3、请勿放置于中文路径下,否则无法启动 4、sbin/nginx -c conf/nginx.conf
Sticky是nginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上,默认标识名为route (a)客户端首次发起访问请求,nginx接收后,发现...
nginx带nginx-http-flv模块,包含所有rtmp功能,我自己在windows下编译的,直接可用,用的是最新版的1.19.4版本
资源说明: 1. 采用nginx最新版编译,包含最新的nginx-http-flv-module,以及基础...1. 将压缩包解压到D:\nginx-1.19.3目录下 2. 使用cmd命令打开DOS,并切换到D:\nginx-1.19.3 3. 使用nginxservice.exe install安装
此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...
nginx1.23.2-麒麟-aarch64
windows下编译nginx-http-flv-moudle,编译好的,下载开箱可用,作者亲测。用于直播推流,浏览器flvjs播放视频,支持无插件flash播放。
添加nginx-http-flv-module模块并重新编译后的nginx(windows版)
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
基于nginx1.19.3版本,已编译好nginx-http-flv-module,开箱即用。鄙视那些收C币的。
nginx + nginx-http-flv-module-1.2.9
nginx-rtmp-module-master源码
nginx-rtmp模块源码包nginx-rtmp-module-master
目前的项目网站架构中使用了F5和nginx,F5用来做负载均衡,nginx只用作反向代理服务器。最近应客户的要求准备去掉F5...上网搜索了一番,知道了nginx-sticky-module这个第三方模块可以基于cookie实现会话保持,决定试试
nginx-1.23.0nginx-1.23.0nginx-1.23.0nginx-1.23.0