apache - 设置好 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,也不知道要使用什么配置或如何进行。
解决方案
您正在寻找的答案在这里:
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
建议您阅读完整的博客文章以了解更多背景信息。
推荐阅读
- android - 在 MainActivity 中加载所有视图后如何自动启动服务?
- validation - 在 Cerberus 验证期间禁用只读
- flask - 如何将 HTML 下拉列表中的值存储到 Flask 中的 MySQL DB
- bash - 添加到现有别名
- perl - Perl,按特定模式拆分字符串
- python - 复制列表中的字符串并将整数后缀添加到新添加的字符串中
- python - PyQt5 中的哪个 Gstreamer?
- twig - 设置 Twig 变量
- serial-port - 使用串行外设接口 (SPI) 同时与多个从机通信
- android - 我想从android将json文件发送到我的服务器我应该在doInBackground方法中做什么?