4

I have a dedicated server installed with CentOS 6.5 Plesk 11.5 and I've turned on Nginx to process PHP files.

I've turned on services in Plesk Tools/Services Management:

  • Reverse Proxy Server (nginx)
  • PHP-FPM support for nginx

and in Domains/example.com/Web Server Settings

  • Smart static files processing
  • Serve static files directly by nginx
  • Process PHP by nginx

I use CodeIgniter Framework, everything works well with default configurations. But when I try to remove index.php in the CodeIgniter config file (config.php)

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

previous URL example.com/project/index.php/text turns into example.com/project/text though I can't access to link and have following error:

No input file specified.

I've searched and there are many solutions, nothing worked for me. Plesk automatically generates Nginx configurations for each domain. According to guides, I've tried adding this code in Additional nginx directives in Domains/example.com/Web Server Settings.

location ~ /project {
     try_files $uri $uri/ /index.php?$args;
 }

I get a different error:

File not found.

What should I change and where? I've wasted 2 days without success.

I have following code in example.com.conf but it's generated automatically by the 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";
}

2 Answers 2

9

I have finally solved a rewrite problem. What it's important, Plesk generates default parameters in Nginx configuration file, any changes inside that file is temporary.

To remove index.php in CodeIgniter projects, just add this code for each project in the Plesk>Domains/example.com/Web Server Settings:

location /category/subcategory {
    try_files $uri $uri/ /category/subcategory/index.php; 
}

and remove index.php parameter in CodeIgniter config.php:

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Sign up to request clarification or add additional context in comments.

2 Comments

for my subfolder project /ci; this solved. However it can't open index.php if mention localhost/ci/ in browser for that i did this: location /ci { index index.html index.htm index.php; try_files $uri $uri/ /ci/index.php; }
Removing value of $indexPage still works on CodeIgniter 4. thanks
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

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

http://localhost/ci/

But this solution worked perfectly for me adding nginx.conf file.

Find something like this:

// 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")

Add below lines after it:

location /ci {
    index  index.html index.htm index.php;
    try_files $uri $uri/ /ci/index.php; 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.