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

标签 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。

最佳答案

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

关于php - 如何从 Codeigniter (nginx) 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36597061/

相关文章:

php - or_like 在 codeIgniter 中不起作用

php - 在 Controller View 中显示变量

php - View 模型中的 ZF2 自定义方法可用于特定模板

php - 未传递给类方法的变量

php - 列名中的特殊字符

php - 一对多的最优数据库结构设计

php - 在 Codeigniter 3 上使用 Eloquent

nginx - 如何禁止通过 IP 地址直接访问网站

django - 如何避免使用 Django、nginx 和 uWSGI 将环境变量放到多个地方?

ruby-on-rails - GitLab API 访问 : Failed to connect to internal API