我有一个带有登录表单的 Codeigniter 应用程序。我在 Apache 和 Nginx 上都运行了它。在 Apache 上,一切正常,表单 Action 正常。但是在 Nginx 上,表单操作使用 https
而不是 http
(我现在不想要)。
我使用这个生成表单:
<?php echo form_open(site_url('/user/do_login')); ?>
它产生这个:
<form action="https://example.com/index.php/user/do_login" method="post" accept-charset="utf-8">
我如何强制它在 Nginx 上生成 http
而不是 https
?
最佳答案
假设您正在使用自动 site_url 检测,Codeigniter 自己的 http/https 检测依赖于 $_SERVER['HTTPS']
value to be off
如果它实际上被设置为某些东西,则为 base_url 生成 http
。
检查您的默认 fastcgi_params(通常是 /etc/nginx/fastcgi_params
),也许它将它设置为空字符串或除“off”之外的其他内容,您也可以通过 nginx 配置强制执行此操作要“关闭”:
fastcgi_param HTTPS off;
如果您在 nginx 的配置文件中为 http 和 https 连接使用一个 server
block ,您可以使用 mapping根据 $scheme
变量创建您需要的值:
# somewhere inside http { ... }
map $scheme $php_https { default off; https on; }
并在fastcgi_param
中引用它:
fastcgi_param HTTPS $php_https;
关于php - Nginx 上的 Codeigniter 为表单生成 https 操作,但不是 Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271137/