我在http://localhost:4242上运行了一个Hunchentoot应用程序。此应用程序使用非SSL受体(即hunchentoot:easy-acceptor而不是hunchentoot:easy-ssl-acceptor)。我将Nginx设置为反向代理,以便使用SSL为该应用程序服务。这是Nginx配置:
server {
listen 443 ssl;
server_name example.test;
ssl_certificate /etc/my-ssl/certs/example.pem;
ssl_certificate_key /etc/my-ssl/private/example.key;
location / {
include /etc/nginx/proxy_params;
proxy_pass http://localhost:4242;
}
}/etc/nginx/proxy_params在哪里
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;问题是Hunchentoot不知道反向代理(即Nginx)实际上正在使用HTTPS为客户端服务。因此,(hunchentoot:redirect "/some-page/")将重定向到http://example.test/some-page/而不是https://example.test/some-page/。Hunchentoot不考虑X-Forwarded-Proto头。
为了解决这个问题,我编写了一个替代的重定向函数,而不是#'hunchentoot:redirect。
(defun my-redirect (target
&rest args
&key (protocol
(if (string= (hunchentoot:header-in* :x-forwarded-proto)
"https")
:https
:http))
&allow-other-keys)
(apply #'hunchentoot:redirect target :protocol protocol args))这是解决问题的正确方法吗?有没有更好的方法?
(Hunchentoot 1.3.0;SBCL 2.2.2;Nginx 1.18.0;Ubuntu 20.04)
编辑:在Hunchentoot的问题跟踪器:使用HTTPS反向代理服务应用程序时将错误重定向到HTTP
发布于 2022-05-04 10:24:25
一个选项是将hunchentoot:easy-acceptor子类化,并为您的受体专门化acceptor-ssl-p方法。这将使您能够调用hunchentoot:redirect并让协议决策在幕后进行。
(defclass my-easy-acceptor (hunchentoot:easy-acceptor)
())
(defmethod hunchentoot:acceptor-ssl-p ((acceptor my-easy-acceptor))
(string= (hunchentoot:header-in* :x-forwarded-proto) "https"))但是,在我看来(从nginx配置中),您总是在为HTTPS服务--因此您可以省略逻辑并始终返回t。
https://stackoverflow.com/questions/72062476
复制相似问题