Friday, June 8, 2018

php - Can't get Codeigniter URLs working on Nginx





After successfully setting up nginx on my windows, another problem where I am stuck. Though, everything works as usual. I am able to access pages and PHP works fine but problem comes when I try to use Codeigniter type urls, by which, I mean,



https://localhost/index.php/


Even if I insert one slash after "index.php" an error No input file specified is thrown which I think means the FastCGI server is not able to catch the right file. Here is my config file,




server {
server_name localhost;
listen 443;
root /wamp/www/;

ssl on;
ssl_certificate /wamp/www/server.crt;
ssl_certificate_key /wamp/www/server.key;


location / {
index index.php index.html index.htm;
}

location /NavHawk2 {
try_files $uri $uri/ index.php/;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#

location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}



Nothing in error logs and access logs are filled with 404 requests. If I remove the try_files line, I get a nginx 404 page.


Answer



Looks like you need to use fastcgi_split_path_info.



An example:



fastcgi_split_path_info       ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...