You are not logged in.

#1 2022-01-09 14:34:39

Iriomote
Member
Registered: 2013-11-10
Posts: 9

nginx and php-fpm installation: throws 404 error

I am trying to set up nginx with php-fpm.

I followd the wiki article but i keep getting 404 errors when i try to request a php-file.
The "open_basedir" in "/etc/php/php.ini" is not set.
It is not a permission problem, the .html files have the same permissions as the php-file.
The only thing I changed was the document root, it is in "/var/www".
"journalctl -u nginx" and the nginx error Log don't yield any useful debug information.

/etc/nginx/niginx.conf:

worker_processes  1;
error_log   /var/log/nginx/error.log;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /var/www;
            index  index.html index.htm index.php;
        }
        include /etc/nginx/php-fpm.conf;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}

/etc/nginx/php-fpm.conf:

location ~ \.php$ {
        # 404
        try_files $fastcgi_script_name =404;

        # default fastcgi_params
        include fastcgi_params;

        # fastcgi settings
        fastcgi_pass                    unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index                   index.php;
        fastcgi_buffers                 8 16k;
        fastcgi_buffer_size             32k;

        # fastcgi params
        fastcgi_param DOCUMENT_ROOT     $realpath_root;
        fastcgi_param SCRIPT_FILENAME   $realpath_root$fastcgi_script_name;
        #fastcgi_param PHP_ADMIN_VALUE  "open_basedir=$base/:/usr/lib/php/:/tmp/";
}

I have no idea what goes wrong there.

Offline

#2 2022-01-09 16:23:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 26,168
Website

Re: nginx and php-fpm installation: throws 404 error

Iriomote wrote:

"journalctl -u nginx" and the nginx error Log don't yield any useful debug information.

Can we be the judge of that?  Also the php-fpm journal entries could be useful.

Note that what you have matches the wiki, but on my setup I have prepended $document_root to $fastcgi_script_name in try_files.  I'm not sure if it's relevant, but you root is also only defined in the "location /" block rather than in the server block.

EDIT: actually the second point almost certainly is relevant, and is quite likely the cause of the problem.

Last edited by Trilby (2022-01-09 16:24:03)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-01-09 17:30:07

Iriomote
Member
Registered: 2013-11-10
Posts: 9

Re: nginx and php-fpm installation: throws 404 error

Trilby wrote:
Iriomote wrote:

"journalctl -u nginx" and the nginx error Log don't yield any useful debug information.

Can we be the judge of that?  Also the php-fpm journal entries could be useful.

Note that what you have matches the wiki, but on my setup I have prepended $document_root to $fastcgi_script_name in try_files.  I'm not sure if it's relevant, but you root is also only defined in the "location /" block rather than in the server block.

EDIT: actually the second point almost certainly is relevant, and is quite likely the cause of the problem.

You were right, the problem was with the "root /var/www;" definition, after I moved it from the location-block to the server-block it worked.
I didn't even need to add the $document_root to the "try_files".

Thank you.


But the journal wasn't really helpful. For reference:

journalctl -u php-fpm:

Jan 09 18:25:46 zabbix php-fpm[838]: [NOTICE] Terminating ...
Jan 09 18:25:46 zabbix php-fpm[838]: [NOTICE] exiting, bye-bye!
Jan 09 18:25:46 zabbix systemd[1]: Stopping The PHP FastCGI Process Manager...
Jan 09 18:25:46 zabbix systemd[1]: php-fpm.service: Deactivated successfully.
Jan 09 18:25:46 zabbix systemd[1]: Stopped The PHP FastCGI Process Manager.
Jan 09 18:25:46 zabbix systemd[1]: Starting The PHP FastCGI Process Manager...
Jan 09 18:25:46 zabbix php-fpm[857]: [NOTICE] fpm is running, pid 857
Jan 09 18:25:46 zabbix php-fpm[857]: [NOTICE] ready to handle connections
Jan 09 18:25:46 zabbix systemd[1]: Started The PHP FastCGI Process Manager.
Jan 09 18:25:46 zabbix php-fpm[857]: [NOTICE] systemd monitor interval set to 10000ms

journalctl -u nginx:

Jan 09 18:25:46 zabbix systemd[1]: Stopping A high performance web server and a reverse proxy server...
Jan 09 18:25:46 zabbix systemd[1]: nginx.service: Deactivated successfully.
Jan 09 18:25:46 zabbix systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jan 09 18:25:46 zabbix systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 09 18:25:46 zabbix systemd[1]: Started A high performance web server and a reverse proxy server.

That was everything I got out of it.

Offline

Board footer

Powered by FluxBB