Welcome! Log In Create A New Profile

Advanced

nginx "file not found" with index.php

Posted by ottaviane 
nginx "file not found" with index.php
February 25, 2016 12:09PM
hello,
I installed nginx in my ubuntu machine, php and fcgiwrap.
I made many modifies to config files to resolv many issues
(403, 404, 502) and now when I open "localhost/index.php"
the error message is "file not found".
with "localhost/index.html" it works.

with tail -f /var/log/nginx/error.log
this is the error: 2016/02/25 18:00:53 [error] 1082#0: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

and if I make sudo netstat -alnp | grep cgi
it says: unix 2 [ ACC ] STREAM LISTENING 13560 918/fcgiwrap /var/run/fcgiwrap.socket

may you help me please?
thanks. bye.
Re: nginx "file not found" with index.php
February 25, 2016 12:25PM
this is my /etc/nginx/sites-enabled/default file

server
{
listen 80;
server_name localhost;
# fast cgi support
include /etc/nginx/fcgiwrap.conf;


location /
{

root /home/ottaviane/Sviluppo/Progetti/HTML-PHP/www.ottaviane.it/www;
index index.php;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html
{

root /home/ottaviane/Sviluppo/Progetti/HTML-PHP/www.ottaviane.it/www;
}

location ~ \.php$
{
#fastcgi_pass unix:/var/run/php5-fpm.sock;
root /home/ottaviane/Sviluppo/Progetti/HTML-PHP/www.ottaviane.it/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/ottaviane/Sviluppo/Progetti/HTML-PHP/www.ottaviane.it/www$fastcgi_script_name;
include fastcgi_params;
}
}





and this is my /etc/nginx/fcgiwrap.conf

# Include this file on your nginx.conf to support debian cgi-bin scripts using
# fcgiwrap
location /cgi-bin/ {
# Disable gzip (it makes scripts feel slower since they have to complete
# before getting gzipped)
gzip off;

# Set the root to /usr/lib (inside this location this means that we are
# giving access to the files under /usr/lib/cgi-bin)
root /usr/lib;

# Fastcgi socket
fastcgi_pass unix:/var/run/fcgiwrap.socket;

# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;

# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME /usr/lib$fastcgi_script_name;
}
Re: nginx "file not found" with index.php
February 26, 2016 08:11AM
Hello,

I'm not certain why you are using fcgiwrap. That is a wrapper for cgi scripts. I'm guessing that you are using php-fpm listening on 127.0.0.1:9000. Unless you are also using some actual cgi scripts (which according to your configuration should be in /usr/lib/cgi-bin), comment out "include /etc/nginx/fcgiwrap.conf; ". You don't need that and it may be setting "fastcgi_param SCRIPT_FILENAME" to an incorrect value.

Also, for maintainability and readability, change:

fastcgi_param SCRIPT_FILENAME /home/ottaviane/Sviluppo/Progetti/HTML-PHP/www.ottaviane.it/www$fastcgi_script_name;

to

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Let's see how that goes.

--
Jim Ohlstein
Re: nginx "file not found" with index.php
February 29, 2016 04:05AM
ok it's all ok.

now I need to change my root directory for my web proj.
infact this is part of my /etc/nginx/sites-enabled/default file



server {
listen 80;
listen [::]:80 default_server ipv6only=on;

#root /usr/share/nginx/html;
root /home/ottaviane/Sviluppo/Progetti/HTML-PHP/html;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name _;
...ecc

with root /home/ottaviane/Sviluppo/Progetti/HTML-PHP/html;
it does'nt work!
but if I set root /usr/share/nginx/html;
it works. The two directory are equals.
why it?

thanks, bye.
Re: nginx "file not found" with index.php
February 29, 2016 04:36AM
with root /home/ottaviane/Sviluppo/Progetti/HTML-PHP/html;
it does'nt work! firefox tells "500 Internal Server Error"
and in nginx.log I can read:
2016/02/29 10:06:45 [crit] 5146#0: *3 stat() "/home/ottaviane/Sviluppo/Progetti/HTML-PHP/www.ottaviane.it/www/index.html" failed (13: Permission denied), client: 127.0.0.1, server: _, request: "GET /index.html HTTP/1.1", host: "localhost"


but if I set root /usr/share/nginx/html;
it works. The two directory are equals.

if I give sudo groups ottaviane
the system tells ottaviane : ottaviane adm cdrom sudo dip www-data plugdev lpadmin sambashare

/home/ottaviane/Sviluppo/Progetti/HTML-PHP/html; proprietary is root:root
/usr/share/nginx/html; proprietary is also root:root



why it?

thanks, bye.
Re: nginx "file not found" with index.php
February 29, 2016 01:26PM
That's a permission error. I'm not sure what you mean by the two directories are "the same" but I would check the permissions of all of the directories in that path. One of the directories is probably not readable by the nginx user.

--
Jim Ohlstein
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 240
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready