简体   繁体   中英

Codeigniter Nginx Controller Functions Returning 404

I am currently running nginx and codeigniter on my server. I can access the base functions,for example

sample.dev/samplecontroller

but when i try to specify a function within that controller,eg

sample.dev/controller/function

I get 404 error

My sites-available file for the project sample.dev is as follows:

server {
listen 80 ;
listen [::]:80;

root /var/www/html/sample_ci;

# Add index.php to the list if you are using PHP
index index.html index.php index.htm index.nginx-debian.html;

server_name sample.dev;

      location / {
           # URLs to attempt, including pretty ones.
           try_files   $uri $uri/ /index.php?$query_string;
    }
   error_page 404 /404.html;
   error_page 500 502 503 504 /50x.html;
   location = /50x.html {
     root /usr/share/nginx/html;
    }

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#   include snippets/fastcgi-php.conf;
    try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
#
#   # With php5-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
            fastcgi_split_path_info         ^(.+\.php)(.*)$;

            include                        /etc/nginx/fastcgi_params;
            fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny all;
}
}

My .htaccess file for the project is also as follows:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sample_ci

RewriteCond %{REQUEST_URI} ^system.*

RewriteRule ^(.*)$ /HCMP/index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

And i have configured the config.php file variables as follows:

$config['base_url'] = 'http://sample.dev/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

The above configuration is not functional despite me following all steps on the official nginx site and on the other posts I have found here. Is there anything im doing wrong or should do?

You cannot use .htaccess files on nginx... those files are mostly for Apache. Therefore, your rewrites are not being used and you will always get a 404.

What you need to know is here:

https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/#
http://www.farinspace.com/codeigniter-nginx-rewrite-rules/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM