[英]Cookies are not sent with request in nginx
I have problem with cookies, nginx and the backend server. Cookie,nginx和后端服务器出现问题。
What I would like to achieve is something like this: 我想要实现的是这样的:
NGINX AT PORT 70
location / {
If session cookie is not set
return 301 localhost/login.html
else
proxy_pass http://somewhere
}
location /login.html{
proxy_pass http://localhost:8080 <- backend server with logging at localhost:8080/login.html
}
location /redirection/ {
return 301 localhost:70
}
so it should go to login.html and proxy the pass to logging server so that I get localhost:8080/login.html and can log in. Then it process the credentials and redirect to /redirection/ in form action (processing is done in JavaScript - it's actually for now setting cookies only). 因此它应该转到login.html并将该通行证代理到日志记录服务器,以便我可以获取localhost:8080 / login.html并可以登录。然后它处理凭据并以表单操作重定向到/ redirection /(在JavaScript-实际上仅用于设置cookie)。 After being in redirection server should send request to itself, but now it has session cookie so it's going to http://somewhere .
重定向后,服务器应该向自身发送请求,但是现在它具有会话cookie,因此它将转到http:// somewhere 。
But mine problem is that in login.html cookies should be set, but they aren't. 但是我的问题是应该在login.html中设置cookie,但是没有设置。 If I'm going to localhost:8080/login.html alone and try - then cookies work well.
如果我要单独访问localhost:8080 / login.html并尝试-那么cookie可以正常工作。 But somehow with
proxy_pass
cookies are lost. 但是以某种方式丢失了
proxy_pass
cookie。
PS If I use two server block and /login.html and /redirection are on this second server it works well, but I can't have two server blocks in my configuration - I need to have everything on one port. PS:如果我使用两个服务器块,并且/login.html和/ redirection在第二台服务器上运行良好,但是我的配置中不能有两个服务器块-我需要将所有内容都放在一个端口上。
Well... I did resolve this issue.. Like I said it was js script setting mine cookies. 好吧...我确实解决了这个问题。就像我说的是设置我的cookie的js脚本。 But it seems that js scripts didn't load as it went straight ahead to "/" location.
但是似乎js脚本没有加载,因为它直接进入“ /”位置。 what I did was:
我所做的是:
location /js/ {
proxy_pass http://localhost:8080;
}
with this everything is working. 这样,一切正常。
So remember.. if Your html files on backend server contain any css/js files You need to take into account that. 所以请记住..如果您在后端服务器上的html文件包含任何css / js文件,则需要考虑到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.