求教如何在反代中指定某目录不走反代,其他的目录走反代

2020-08-24 18:41:23 +08:00
 PerFectTime

需求: 使用 nginx 反代 wordpress,证书使用 Let's Encrypt,SSL 证书更新使用 acme.sh

问题: 使用 acme.sh 更新时,无法访问到.well-known 目录导致无法续期证书

试过指定以下配置,访问不到

  location /.well-known {
    root /path/to/web;
  }

  location /.well-known/ {
    root /path/to/web;
  }

  location ~/.well-known {
    root /path/to/web;
  }

现有配置:

  location / {
    proxy_pass http://wordpress;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-proto https;
    proxy_redirect off;
  }

957 次点击
所在节点    NGINX
2 条回复
PerFectTime
2020-08-25 10:23:29 +08:00
= =解决了,通过 try files 可以解决这个问题

location /.well-known {
try_files $uri $uri/ @backend;
}

location / {
proxy_pass http://wordpress;
}

location @backend {
proxy_pass http://wordpress;
}
PerFectTime
2020-08-25 10:33:15 +08:00
精简一下似乎也是可以的

location /.well-known {
try_files $uri $uri/ /;
}

location / {
proxy_pass http://wordpress;
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/701044

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX