首页 > 解决方案 > 设置好 NGINX 反向代理后,如何在引入 NGINX 反向代理的 NGINX 上配置 SSL 直通?

问题描述

我有一个用于各种个人项目的内部 LAMP (Ubuntu 18.04) 服务器。它一直直接暴露在端口 80 和 443 上。它托管 4 个站点(Apache 虚拟主机),我对域使用 CloudFlare 完整 SSL。我使用 certbot 发布了 Let's Encrypt 证书。这一切都是按照在线教程完成的,因为我从来都不是系统管理员。

昨晚一个朋友安装了 NGINX 服务器,端口 80 和 443 上的所有流量都转到它。我们正在一起开展一些项目,现在我的网络中有几台服务器,因此使用了 nginx 反向代理。我被要求简单地使用 ssl passthrough 来重新启用对我的站点的访问。

我知道配置文件的位置,我知道如何重新启动 nginx 服务,但仅此而已。我从未使用过 NGINX,也不知道要使用什么配置或如何进行。

标签: apachesslnginxreverse-proxy

解决方案


您正在寻找的答案在这里:
https ://reinout.vanrees.org/weblog/2017/05/02/https-behind-proxy.html

总之,这里是您需要的配置选项。

server {
  listen 443;
  server_name sitename.example.org;
  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_redirect off;
    proxy_pass https://internal-server-name;
    proxy_http_version 1.1;
  }
  ssl on;
  ....
  ssl_certificate /etc/ssl/certs/wildcard.example.org.pem;
  ssl_certificate_key /etc/ssl/private/wildcard.example.org.key;
}

当然,您需要在代理服务器上设置 SSL,但这是基本思想。

值得注意的是,默认情况下 nginx 将使用 HTTP/1.0 进行代理。这就是为什么你需要proxy_http_version

建议您阅读完整的博客文章以了解更多背景信息。


推荐阅读