You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已解决:Nginx无法将https://www域名请求重定向到https://根域名

Nginx HTTPS域名重定向故障修复方案

故障原因

你的https://www.example.dev重定向故障是由Nginx内置变量拼写错误导致的:
你在server_name=www.example.dev的443端口server块中,错误将获取请求路径的内置变量$request_uri写为$request.uri。Nginx无法识别不存在的变量时,会直接将变量名作为普通字符串拼接到重定向地址中,由此导致Chrome出现https://example.devget%20/%20HTTP/2.0.uri这类异常跳转地址,Firefox则会检测到传输异常拦截访问。

修复步骤

  1. 找到对应server块配置:
server {
    listen 443 ssl http2;
    server_name www.example.dev;
    ssl_certificate /etc/letsencrypt/live/example.dev/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.dev/privkey.pem;
    # 下面这行是错误配置
    return 301 https://example.dev$request.uri;
}
  1. 修改重定向规则,将$request.uri替换为正确的$request_uri:
return 301 https://example.dev$request_uri;
  1. 执行命令验证配置合法性并重载Nginx:
# 验证配置语法是否正确
nginx -t
# 重载配置生效
nginx -s reload

内容的提问来源于stack exchange,提问作者monstereo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 01:54:06