大网数据广告活动
服务器运维问答

nginx load balancer w/ https and lets encrypt cert renewal

· 52CE 我爱测

I have a small Linux VPS instance set up with nginx to proxy requests as a load balancer to multiple application servers. All traffic is coming into https://app.example.com proxied to those upstream servers. Example nginx configu…

问题原文

原帖链接 · beaorn · CC BY-SA 3.0

I have a small Linux VPS instance set up with nginx to proxy requests as a load balancer to multiple application servers.

All traffic is coming into https://app.example.com proxied to those upstream servers. Example nginx configuration for the load balancer:

upstream app_servers {
    server app-1.example.com;
    server app-2.example.com;
}

server {
    listen 80;
    listen 443 ssl;
    include snippets/ssl-app.example.com.conf;
    include snippets/ssl-params.conf;

    server_name app.example.com;

    root /var/www/html;

    location / {
            # Set proxy headers
            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_pass http://app_servers;
    }

    location ~ /.well-known {
            allow all;
    }

}

I set up letsencrypt and got certificate for app.example.com before setting up proxy and now I'm having trouble figure out how to configure nginx to proxy everything to the upstream app_servers except for anything to /.well-known so certbot can locally renew the SSL certificates on the server running this nginx load balancer. Any suggestions on how to route app.example.com/.well-known/ to a local path that letsencrypt certbot can use and hit successfully during renewal?


Update ensuring .well-known existed at /var/www/html (Debian) and setting root in conf allowed the certbot to renew properly. nginx conf snippet updated to reflect that.

已采纳解答

原帖链接 · beaorn · CC BY-SA 3.0

Setting root to the default nginx webroot on Debian /var/www/html where certbot was originally configured to be pointed at for the .well-known folder resolved the issue.

upstream app_servers {
  server app-1.example.com;
  server app-2.example.com;
}

server {
  listen 80;
  listen 443 ssl;
  include snippets/ssl-app.example.com.conf;
  include snippets/ssl-params.conf;

  server_name app.example.com;

  root /var/www/html;

  location / {
    # Set proxy headers
    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_pass http://app_servers;
  }

  location ~ /.well-known {
    allow all;
  }
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。