php - Nginx 上的 Codeigniter 为表单生成 https 操作,但不是 Apache

标签 php apache codeigniter https nginx

我有一个带有登录表单的 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/

相关文章:

CodeIgniter update() 默认为 insert()

php - 在网站结构中找到 "orphan"文件

php - 如何检测文件名中的常见字符串组

php - 为什么使用 Tomcat 而不是常规的 Apache Web 服务器

linux - linux 服务器中 mod_qos 配置(.conf)的位置是什么?

php - codeigniter 如何为 Controller 类和方法设置路由?

php - WordPress : ERROR: "Table Prefix" must not be empty

php - 划分 foreach 不能正常工作

java - Apache 的 FileHandler 保存 unicode 转义符而不是特殊字符

codeigniter - 上游太大 - nginx + codeigniter