hyperf / hyperf/hyperf-docker

请问一下使用nginx反向代理后sessionid每次请求都会改变

オープン
#70 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Dockerfile
スター
348
フォーク
201
PR マージ指標
30日以内にマージされた PR はありません

説明

Nginx
`
upstream hyperf {
ip_hash; # 启用会话保持
# Hyperf HTTP Server 的 IP 及 端口
server 127.0.0.1:9581;
}

server {
listen 80;
server_name www.ascore.local;

charset utf-8;

access_log /usr/local/var/log/nginx/ascore/access.log;
error_log /usr/local/var/log/nginx/ascore/error.log;

# 忽略 favicon.ico 请求,直接反向代理给 Hyperf
location = /favicon.ico {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cookie_path / "/; secure; HttpOnly; SameSite=Lax";
proxy_pass http://hyperf;
}

# 处理 CSS 请求,直接反向代理给 Hyperf
location ~* \.css$ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cookie_path / "/; secure; HttpOnly; SameSite=Lax";
proxy_pass http://hyperf;
}

# 处理 JS 请求,直接反向代理给 Hyperf
location ~* \.js$ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cookie_path / "/; secure; HttpOnly; SameSite=Lax";
proxy_pass http://hyperf;
}

# 处理图片请求,直接反向代理给 Hyperf
location ~* \.(jpg|jpeg|png|gif|svg)$ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cookie_path / "/; secure; HttpOnly; SameSite=Lax";
proxy_pass http://hyperf;
}

location / {
# 重写规则
if ($request_uri ~* ^/en(/|$)) {
rewrite ^/(.*)$ /404 break;
}
rewrite ^/(.*)/$ /$1 permanent;
rewrite ^/(en|hi)$ /$1 break;
rewrite ^/(en|hi)/(.*)$ /$1/$2 break;
rewrite ^/$ /en last;
if ($request_uri !~* ^/(en|hi)/) {
rewrite ^/(.*)$ /en/$1 last;
}
# 将客户端的 Host 和 IP 信息一并转发到对应节点
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie; # 保持原有的Cookie

# 转发Cookie,设置 SameSite
proxy_cookie_path / "/; secure; HttpOnly; SameSite=Lax";

# 执行代理访问真实服务器
proxy_pass http://hyperf;
}
}
`
session
`return [
'handler' => Handler\FileHandler::class,
'options' => [
'connection' => 'default',
'path' => BASE_PATH . '/runtime/session',
'gc_maxlifetime' => 1200,
'session_name' => 'HYPERF_SESSION_ID',
'domain' => null,
'cookie_lifetime' => 5 * 60 * 60,
'cookie_same_site' => 'lax',
],
];`

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

No repository file or test is identified. Start by reproducing the changing session ID with the supplied Nginx reverse-proxy configuration and session settings, then inspect the request and response cookies across repeated requests. Done means the cause is isolated and a concrete configuration or project change is documented.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
nginx
領域
backend, infrastructure
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。