如何从Codeigniter中删除index.php(nginx)

时间:2016-04-13 11:31:23

标签: php codeigniter nginx

我正在尝试使用Codeigniter连接nginx服务器删除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。

1 个答案:

答案 0 :(得分:0)

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";