[英]Nginx Reverse proxy not redirecting to HTTPS
所以我有一个 Nginx 服务器作为反向代理使用这个配置
http {
server {
listen 80;
listen [::]:80;
server_name www.example.tdl;
access_log logs/reverse-access.log;
error_log logs/reverse-error.log;
location / {
proxy_pass https://127.0.0.1:443;
}
}
}
我唯一的问题是,当我连接到 example.tdl 时,它会正确重定向,但不会使用 HTTPS。 但它重定向到我的 Apache 服务器的 https 端口,所以我不知道问题出在哪里。 我以前从未使用过 nginx 所以这可能是配置错误。
如何使用 https 使 nginx 重定向到该端口?
这听起来可能很愚蠢,但你得到的是nginx
正在为你工作。 You connect to nginx
via HTTP, nginx
forwards your request to apache
via HTTPS, then gets the answer back and transmit it to you using HTTP.
你需要让nginx
监听 HTTPS listen 443 ssl;
并为其提供证书( ssl_certificate <path>;
)和密钥( ssl_certificate_key <path>;
)。 之后将以下代码添加到服务器块:
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
这会将所有内容重定向到 HTTPS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.