【问题标题】:How to remove index.php from Codeigniter (nginx)如何从 Codeigniter (nginx) 中删除 index.php
【发布时间】:2016-04-13 11:31:22
【问题描述】:

我正在尝试使用带有 nginx 服务器的 Codeigniter 删除 index.php?,但它不起作用。我尝试了nginx网站https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/的官方解决方案 实际上,在默认文件中,我有以下代码:

server {
        listen 99 default_server;
        listen [::]:99 default_server ipv6only=on;

        root /var/www;
        index index.html index.htm index.php;
        autoindex on;
        # Make site accessible from http://localhost/
        server_name localhost;



        index index.php;
location / {
    set $page_to_view "/index.php";
    try_files $uri $uri/ @rewrites;
    root   /var/www/site;
    index  index.php index.html index.htm;
}

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/site$page_to_view;
}

# rewrites
location @rewrites {
    if ($uri ~* ^/([a-z]+)$) {
        set $page_to_view "/$1.php";
        rewrite ^/([a-z]+)$ /$1.php last;
    }
}

}

而config.php文件如下:

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

任何请求的结果都是 502 Bad Gateway。

【问题讨论】:

    标签: php codeigniter nginx


    【解决方案1】:
    server {
        listen       80;
        server_name  localhost;
        root   /var/www/html/ci;
        autoindex on;
        index index.php;
    
        location / {
    
            try_files $uri $uri/ /index.php;
    
            location = /index.php {
    
                fastcgi_pass   127.0.0.1:6969;
                fastcgi_param  SCRIPT_FILENAME /var/www/html/ci$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
    
        location ~ \.php$ {
            return 444;
        }
    

    }

    和配置文件

      $config['base_url'] = "";
      $config['index_page']       = "";
      $config['uri_protocol']     = "AUTO";
    

    【讨论】:

    • 感谢 Muhammad,但我之前尝试实施此解决方案,但它不起作用。也许我必须澄清一下我实现了nginx官方解决方案
    猜你喜欢
    • 2021-03-18
    • 1970-01-01
    • 2016-07-05
    • 2012-08-10
    • 2015-10-24
    • 2014-09-20
    • 1970-01-01
    • 2018-03-18
    • 2012-12-19
    相关资源
    最近更新 更多