gpt4 book ai didi

nginx - 有什么方法可以让您的 nginx 代理不转发 HTTP -> HTTPS 仅针对特定 URL?

转载 作者:行者123 更新时间:2023-12-01 07:25:44 26 4
gpt4 key购买 nike

我为 VHOST 启用了自动 SSL,但我需要为只需要接受非 SSL 请求的特定 URL 禁用它。

如果特定的旧 URL 是 HTTPS,那么放入 vhosts 就可以正常工作,但它是 HTTP。我不能使用 HTTPS_METHOD=noredirect 为整个 VHOST 禁用自动 SSL。是否可以针对此自定义 nginx 位置的上下文禁用它?我可以在 nginx-proxy 日志中看到它甚至在达到此 nginx 自定义之前就收到了 301。所以不幸的是,我只能让这个 proxy_pass 配置使用 HTTPS URL,而不是 HTTP。

感谢您的帮助。

location /specific/old/http/URL {
proxy_pass http://service.new.tld/new;
proxy_set_header host http://service.new.tld;
proxy_ssl_certificate /etc/nginx/certs/new.tld/fullchain.pem;
proxy_ssl_certificate_key /etc/nginx/certs/new.tld/key.pem;
}

location /upstream {
proxy_pass http://service.new.tld;
proxy_ssl_certificate
/etc/nginx/certs/service.new.tld/fullchain.pem;
proxy_ssl_certificate_key
/etc/nginx/certs/service.new.tld/key.pem;
}

最佳答案

您需要为 http 和 https 设置一个服务器指令(将监听 80 和 443),并且您只需要在需要的位置添加重定向脚本。参见示例:

server {
listen 80;
listen 443 ssl;
server_name example.com www.example.com;
ssl on;
ssl_certificate example.crt;
ssl_certificate_key example.key;


location /specific/old/http/URL {
proxy_pass http://service.new.tld/new;
proxy_set_header host http://service.new.tld;
proxy_ssl_certificate /etc/nginx/certs/new.tld/fullchain.pem;
proxy_ssl_certificate_key /etc/nginx/certs/new.tld/key.pem;
}

location /upstream {
# add this condition only on the locations you want to redirect to https
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}

proxy_pass http://service.new.tld;
proxy_ssl_certificate /etc/nginx/certs/service.new.tld/fullchain.pem;
proxy_ssl_certificate_key /etc/nginx/certs/service.new.tld/key.pem;
}

关于nginx - 有什么方法可以让您的 nginx 代理不转发 HTTP -> HTTPS 仅针对特定 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58701863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com