【问题标题】:Codeigniter on Nginx generates https action for form, but not ApacheNginx 上的 Codeigniter 为表单生成 https 操作,但不是 Apache
【发布时间】:2012-10-27 14:13:27
【问题描述】:

我有一个带有登录表单的 Codeigniter 应用程序。我在 Apache 和 Nginx 上都运行了它。在 Apache 上,一切正常,表单操作也正常。但在 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

【问题讨论】:

    标签: php apache codeigniter https nginx


    【解决方案1】:

    假设您使用的是自动 site_url 检测,Codeigniter 自己的 http/https 检测依赖于 $_SERVER['HTTPS'] value to be off(如果它实际上设置为某个值)来为 base_url 生成 http

    检查你的默认 fastcgi_params(通常是/etc/nginx/fastcgi_params),也许它将它设置为一个空字符串或“off”以外的其他东西,你也可以从 nginx 配置中强制它为“off”:

    fastcgi_param  HTTPS off;
    

    如果您在 nginx 的配置文件中为 http 和 https 连接使用一个 server 块,则可以使用 mapping 根据 $scheme 变量创建所需的值:

    # somewhere inside http { ... }
    map $scheme $php_https { default off; https on; }
    

    并在fastcgi_param中引用:

    fastcgi_param  HTTPS $php_https;
    

    【讨论】:

    • 我将它从 nginx 配置强制到 off,现在已经解决了!谢谢大佬。
    【解决方案2】:

    在 Nginx 和 Apache 上检查你的 config.php。 site_url 返回您在 config.php 中的 $config['base_url'] 条目中指定的内容

    【讨论】:

    • 你也对,但是如果为空CodeIgniter会尝试自动检测base_url
    猜你喜欢
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 2020-02-18
    • 2014-12-01
    相关资源
    最近更新 更多