我正在 Fedora 上使用 Podman 在服务前面设置反向代理。问题是当我将位置设置为时,/
一切都正常,但当我添加子目录时,/read/
我收到不同的错误。
这是 nginx 配置:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 80 default_server;
listen [::]:80 default_server;
error_log /var/log/nginx/err.log notice;
access_log /var/log/nginx/acc.log;
location /read/ {
proxy_pass http://127.0.0.1:8000/read/;
proxy_set_header X-Forwarded-Host 127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
以及尝试访问服务时的响应:
curl --noproxy "127.0.0.1" -v http://127.0.0.1:8080/read/
* Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
> GET /read/ HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/8.6.0
> Accept: */*
>
< HTTP/1.1 303 See Other
< Server: nginx/1.27.3
< Date: Fri, 24 Jan 2025 21:57:28 GMT
< Content-Length: 0
< Connection: keep-alive
< Cache-Control: private
< Content-Security-Policy: base-uri 'none'; default-src 'self'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; img-src 'self' data:; media-src 'self' data:; object-src 'none'; report-uri http://127.0.0.1:8080/logger/csp-report; script-src 'report-sample' 'nonce-89583bebc2e348ba85f0ef7463e3162c' 'unsafe-inline'; style-src 'report-sample' 'nonce-89583bebc2e348ba85f0ef7463e3162c' 'unsafe-inline'
< Location: http://127.0.0.1:8080/login?r=%2Fread%2F
< Permissions-Policy: interest-cohort=()
< Referrer-Policy: same-origin, strict-origin
< Set-Cookie: sxid=MTczNzc1NTg0OHwwajkzbFhpXzVtc2ZQVnh6bWNJdEllbWlrcm5pVl9Zb1pvZkl1TjN1U1MwZDVNN2ZOQ1F0WHRDT214dTNsY1RPRUl2RHg3UmRlSlB2SVFSWm1UdGQwcm9zSEF1bkFGdVB4dlJpU2p0M1dnPT18HfAf2yi5rBri3VK6LK5cOogYr1mqjogyBFa4Z8BM-2I=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; HttpOnly; SameSite=Lax
< Vary: Accept-Encoding
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-Robots-Tag: noindex, nofollow, noarchive
< X-Xss-Protection: 1; mode=block
<
* Connection #0 to host 127.0.0.1 left intact
您的应用程序假定应用程序的根目录是
/
。当它收到对的请求时/read/
,它会将重定向发送到/login/r=$2fread%2f
。这是应用程序的登录页面,其中包含/read/
登录后重定向到的指令。您需要将应用程序的根 URL 配置为
http://127.0.0.1/read/
。这样您的应用程序就可以正确了解上下文。