如何在 Perl CGI 中编码以包含使用 https 而不是 http 的操作

How to code in Perl CGI to include action with https, not http

我在负载平衡器后面有一台服务器。 LB 将 https 转换为 http,因此 Web 服务器只能看到 http。

我有一个使用 CGI 标准生成输入表单的 perl 脚本

start_form( -action=>url())

现在,HTML 中的 url 指向 url 的 http 版本,而不是 https。让它始终使用 https 的最简洁方法是什么(如果用户正在使用 https)?

我已经尝试将“-rewrite”同时设置为 0 和 1,但没有任何区别。

至少根据 CGI.pm 的文档和代码,如果提供了 CGI 脚本,url()url( full => 1) 都应该 return https://来自 https:// URL。如果负载均衡器剥离 https 并且不提供适当的 headers,您可以将 $ENV{HTTPS} 设置为 ON 以在您的脚本中自己伪造它:

#!perl
use strict;
use warnings;

use CGI qw(url);

$ENV{HTTPS} = 'ON';
print url();

另见

CGI