V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
PerFectTime
V2EX  ›  NGINX

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

  •  
  •   PerFectTime · 2020-08-24 18:41:23 +08:00 · 933 次点击
    这是一个创建于 1333 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需求: 使用 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;
      }
    
    
    PerFectTime
        1
    PerFectTime  
    OP
       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
        2
    PerFectTime  
    OP
       2020-08-25 10:33:15 +08:00
    精简一下似乎也是可以的

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

    location / {
    proxy_pass http://wordpress;
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5183 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 08:25 · PVG 16:25 · LAX 01:25 · JFK 04:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.