Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前后端分离部署时,登录功能失效 #15

Open
AIpolaris opened this issue Nov 25, 2022 · 9 comments
Open

前后端分离部署时,登录功能失效 #15

AIpolaris opened this issue Nov 25, 2022 · 9 comments

Comments

@AIpolaris
Copy link

当前端和后端分离部署,即部署在两台机器上时,登录之后任然会显示未登录,可能是session作用域的问题

@lvhaosir6
Copy link

表示部署在同一台都失效了,但是在本机启动时可以。

@heyi-byte
Copy link

有结果了吗

@a870368162
Copy link

有没有可能是与谷歌浏览器不兼容,换个浏览器试试

@wushiwe-beep
Copy link

如果部署后没办法登录的原因是因为nginx导致的两次cookie不同。
我这边用的是nginx部署的,最后是修改了这部分就成功了
location /api {
proxy_pass http://localhost:8102/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cookie_path / /;
proxy_set_header Cookie $http_cookie;
proxy_cookie_flags ~ nosecure samesite=strict; }

@AIpolaris
Copy link
Author

如果部署后没办法登录的原因是因为nginx导致的两次cookie不同。 我这边用的是nginx部署的,最后是修改了这部分就成功了 location /api { proxy_pass http://localhost:8102/api; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-PORT $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cookie_path / /; proxy_set_header Cookie $http_cookie; proxy_cookie_flags ~ nosecure samesite=strict; }

使用此方法解决部署时不能登录的问题

@a877429929
Copy link

还是不行

@AIpolaris
Copy link
Author

还是不行

如果是使用了nginx的话可以参考一下上面nginx的配置,我这边使用了之后可以解决了

@wdx6
Copy link

wdx6 commented Apr 20, 2023

我用这个方法也不行。不知道怎样设置,我看请求标头上并没有cookie,但是通过IDEA运行是有的

@edanhuang
Copy link

那是因为你前端调后端接口的URI前缀不一样导致的,需要在后端的配置文件里加上你nginx配置的后端接口前缀:

server:
  address: 0.0.0.0
  port: 8102
  servlet:
    context-path: /api  # here
    # session 30 天过期
    session:
      timeout: "P30D"
      cookie:
        same-site: none
        secure: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants