Nginx CodeIgniter删除URL中的index.php

ikz*_*kzi 4 codeigniter nginx plesk

我有一个安装了CentOS 6.5 Plesk 11.5的专用服务器,我已经打开Nginx来处理PHP文件.

我在Plesk 工具/服务管理中打开了服务:

  • 反向代理服务器(nginx)
  • PHP-FPM支持nginx

并在Domains/example.com/Web服务器设置中

  • 智能静态文件处理
  • 由nginx直接提供静态文件
  • 由nginx处理PHP

我使用CodeIgniter Framework,一切都适用于默认配置.但是当我尝试删除CodeIgniter配置文件中的index.php时(config.php)

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Run Code Online (Sandbox Code Playgroud)

以前的URL example.com/project/index.php/text变成了example.com/project/text但我无法访问链接并出现以下错误:

没有指定输入文件.

我搜索过,有很多解决方案,没有什么对我有用.Plesk自动为每个域生成Nginx配置.根据指南,我尝试在Domains/example.com/Web Server Settings中的附加nginx指令中添加此代码.

location ~ /project {
     try_files $uri $uri/ /index.php?$args;
 }
Run Code Online (Sandbox Code Playgroud)

我得到一个不同的错误:

文件未找到.

我应该改变什么,在哪里?我浪费了2天没有成功.

我在example.com.conf中有以下代码,但它是由Plesk自动生成的.

server {
    listen IP_IS_HIDDEN:80;

    server_name domain.com;
    server_name www.example.com;
    server_name ipv4.example.com;


    client_max_body_size 128m;


    root "/var/www/vhosts/example.com/httpdocs";
    access_log /var/www/vhosts/system/example.com/logs/proxy_access_log;


    if ($host ~* ^www.example.com$) {
        rewrite ^(.*)$ http://example.com$1 permanent;
    }

    location / {
        proxy_pass http://IP_IS_HIDDEN:7080;
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        access_log off;
    }

    location @fallback {
        proxy_pass http://IP_IS_HIDDEN:7080;
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        access_log off;
    }

    location ~ ^/plesk-stat/ {
        proxy_pass http://IP_IS_HIDDEN:7080;
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        access_log off;
    }

    location ~ ^/(.*\.(ac3|avi|bmp|bz2|css|cue|dat|doc|docx|dts|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|swf|tar|tgz|txt|wav|xls|xlsx|zip))$ {
        try_files $uri @fallback;
    }

    location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
        alias /var/www/vhosts/example.com/web_users/$1/$2;
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass "unix:/var/www/vhosts/system/example.com/php-fpm.sock";
        include /etc/nginx/fastcgi.conf;    }

    location ~ ^/~(.+?)(/.*)?$ {
        proxy_pass http://IP_IS_HIDDEN:7080;
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        access_log off;
    }

    location ~ \.php(/.*)?$ {
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass "unix:/var/www/vhosts/system/example.com/php-fpm.sock";
        include /etc/nginx/fastcgi.conf;    }

    location ~ /$ {
        index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
    }


    include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";
}
Run Code Online (Sandbox Code Playgroud)

ikz*_*kzi 7

我终于解决了重写问题.重要的是,Plesk在Nginx配置文件中生成默认参数,该文件中的任何更改都是临时的.

要删除CodeIgniter项目中的index.php,只需在Plesk> Domains/example.com/Web Server设置中为每个项目添加此代码:

location /category/subcategory {
    try_files $uri $uri/ /category/subcategory/index.php; 
}
Run Code Online (Sandbox Code Playgroud)

并删除CodeIgniter config.php中的index.php参数:

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Run Code Online (Sandbox Code Playgroud)


Ami*_*hah 6

SOLVED

If my project folder is /ci inside /html directory under nginx,

The above answer by @ikxi worked to open the page like

http://localhost/ci/welcome
Run Code Online (Sandbox Code Playgroud)

However it was not opening index.php if i just type

http://localhost/ci/
Run Code Online (Sandbox Code Playgroud)

但是此解决方案对我添加nginx.conf文件非常有效。

找到这样的东西:

// This lines will be there
location / {
    root   html;
    index  index.html index.htm index.php;
}
// just keep above as it is.. (or you can add "index.php")
Run Code Online (Sandbox Code Playgroud)

在其后添加以下行:

location /ci {
    index  index.html index.htm index.php;
    try_files $uri $uri/ /ci/index.php; 
}
Run Code Online (Sandbox Code Playgroud)