Friday, June 21, 2019

php fpm - NGINX accessing the files in the wrong path

I have a codeigniter application that has the following directory structure




|_
| |_
| |_index.php
|_



The developers have an index.html in the , and directories. The codeigniter files and the services rolled out by the developers are in the directories. The developers access the services by appending the service name to the domain as follows http://mydomain/web/API/index.php/v1/GetRoles The host name is configured as a BASE PATH variable in a javascript file.



This app is served by NGINX running fast-cgi.



Though the HTML pages get loaded no data is being fetched. So we tried accessing the functions by typing the URL in the browser (http://mydomain/web/API/index.php/v1/GetRoles). We get a 404 Not Found error. The error logs contain the following entries



2016/05/20 16:14:57 [error] 2127#0: *232 FastCGI sent in stderr: "Unable to open primary script: /home/myname/public_html/domainname/public/projectname/index.php (No such file or directory)" while reading response header from upstream, client: 14.141.163.46, server: mydomain.com, request: "GET /web/API/v1/get/Common/GetActivities HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomain.com"


The server should be looking for index.php in /home/myname/public_html/domainname/public/projectname/web/API/index.php instead its looking for it in the WEB ROOT.




My NGINX configuration is as follows



server {
listen mydomain.com;
server_name mydomain.com;
root /home/myname/public_html/domainname/public/projectname;

keepalive_timeout 70;
access_log /home/myname/public_html/domainname/log/access.log;

error_log /home/myname/public_html/domainname/log/error.log;

gzip_static on;

index index.html index.php;

location / {
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/www;
}

# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
#try_files $uri =404;

#fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
}
}



I am unable to figure out why NGINX is looking for index.php in the WEB ROOT instead of loading whatever we type in the URL. Look forward to hear from anyone who have faced a similar problem.

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...