[NGINX + PHP-FPM] File not found (résolu)

Questions et astuces concernant l'installation et la configuration d'archlinux
XunilunG
Hankyu
Messages : 11
Inscription : ven. 21 nov. 2014, 08:20

[NGINX + PHP-FPM] File not found (résolu)

Message par XunilunG »

Bonjour le forum,

Après beaucoup de lecture et d'essais , je n'arrive toujours pas à demander une page en php au serveur, il me renvoie une erreur "file not found".

Remarque : si je demande un fichier index.html ça semble fonctionner mais un index.php,non : le navigateur affiche "file not found"

EDIT : je précise que le serveur est dans mon réseau local et que je demande la page via le nom de domaine : nimajneb.eu (et non par l'ip locale)

J'ai lu , entre autre, ce fil : viewtopic.php?p=179905&hilit=php+fpm+nginx#p179905
qui ressemble au souci que je rencontre et qui fait douter sur le paramétrage correct des permissions/utilisateurs .... :(


Vous trouverez ci-dessous les infos que je pense pertinentes pour vous aider à y voir plus clair ...
Je suis désolé, j'espère que c'est assez digeste :( :(

Syntaxe des fichiers de configurations :

Code : Tout sélectionner

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# php-fpm -t
[NOTICE] configuration file /etc/php/php-fpm.conf test is successful
fichier de conf dans /sites-enabled/

Code : Tout sélectionner

 
# cat /etc/nginx/sites-enabled/nimajneb.eu

server {
       
       server_name nimajneb.eu;
       location / {
                root /srv/www/nimajneb.eu;
                index index.html index.php;
                }

        location ~ \.php$ {
        fastcgi_pass  unix:/run/php-fpm/php-fpm.sock;
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi.conf;
	}
}
configuration dans /etc/php/php-fpm.d/

Code : Tout sélectionner

$ cat /etc/php/php-fpm.d/nimajneb.eu.conf
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www.nimajneb.eu]

; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool

; Unix user/group of the child processes. This can be used only if the master
; process running user is root. It is set after the child process is created.
; The user and group can be specified either by their name or by their numeric
; IDs.
; Note: If the user is root, the executable needs to be started with
;       --allow-to-run-as-root option to work.
; Default Values: The user is set to master process running user by default.
;                 If the group is not set, the user's group is used.
user = http
group = http

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.

listen = /run/php-fpm/php-fpm.sock
;listen = 127.0.0.1:9000
Droits et permissions des répértoires :

Code : Tout sélectionner

$ ls -la /srv/
total 24
drwxr-xr-x  6 root root 4096 15 nov.   2021 .
drwxr-xr-x 18 root root 4096 29 juil. 13:21 ..
dr-xr-xr-x  4 root root 4096  7 sept.  2022 ftp
drwxr-xr-x  2 root root 4096 11 nov.   2021 http
drwxr-xr-x  2 root root 4096 13 oct.   2021 partage_arch
drwxr-xr-x  3 root root 4096  5 août  17:26 www

$ ls -la /srv/www/nimajneb.eu/
total 24
drwxr-xr-x 3 pegasi http   4096  5 août  18:09 .
drwxr-xr-x 3 root   root   4096  5 août  17:26 ..
drwxr-xr-x 2 pegasi pegasi 4096 30 juil. 20:20 images
-rw-r--r-- 1 pegasi pegasi   46  5 août  18:06 index.html.save
-rw-r--r-- 1 pegasi pegasi   43  5 août  16:54 index.php
-rw-r--r-- 1 pegasi pegasi   45  5 août  15:28 index.php~

Code : Tout sélectionner

$ ps -ef | grep php
root         651       1  0 16:59 ?        00:00:00 php-fpm: master process (/etc/php/php-fpm.conf)
http         652     651  0 16:59 ?        00:00:00 php-fpm: pool www.nimajneb.eu
http         653     651  0 16:59 ?        00:00:00 php-fpm: pool www.nimajneb.eu
pegasi      1131     298  0 18:36 pts/0    00:00:00 grep php


$ ps -ef | grep nginx
root         682       1  0 17:01 ?        00:00:00 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;
http         683     682  0 17:01 ?        00:00:00 nginx: worker process
pegasi      1152     298  0 18:39 pts/0    00:00:00 grep nginx

Code : Tout sélectionner

$ ls /run/php-fpm/
php-fpm.sock

J'espère ne pas oublier d'information utile..
Merci par avance pour votre aide, vos conseils,vos remarques ou vos critiques .
51peg_b.
Dernière modification par XunilunG le dim. 06 août 2023, 00:19, modifié 1 fois.
Avatar de l’utilisateur
benjarobin
Maître du Kyudo
Messages : 17239
Inscription : sam. 30 mai 2009, 15:48
Localisation : Lyon

Re: [NGINX + PHP-FPM] File not found

Message par benjarobin »

Bonjour,
Peux tu donner la configuration de nginx /etc/nginx/nginx.conf ?
Tu as donné un fichier nimajneb.eu, mais ce n'est pas la configuration principale de nginx.
Note : Par défaut sous Arch le dossier sites-enabled n'existe pas que je sache
Zsh | KDE | PC fixe : core i7, carte nvidia
Titre d'un sujet : [Thème] Sujet (état) / Règles du forum
XunilunG
Hankyu
Messages : 11
Inscription : ven. 21 nov. 2014, 08:20

Re: [NGINX + PHP-FPM] File not found

Message par XunilunG »

Bonjour et merci benjarobin !

J'ai édité le premier post pour ajouter des infos mais je savais que j'allais oublier quelque chose ...

Voici :

Code : Tout sélectionner

$ cat /etc/nginx/nginx.conf

#user http;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;



                # CONFIGURATION PERSO
                include /etc/nginx/sites-enabled/*;

    #gzip  on;

#    server {
 #       listen       80;
  #      server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

   #     location / {
    #        root   /usr/share/nginx/html;
     #       index  index.html index.htm;
      #  }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
       # error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
         #   root   /usr/share/nginx/html;
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
Avatar de l’utilisateur
benjarobin
Maître du Kyudo
Messages : 17239
Inscription : sam. 30 mai 2009, 15:48
Localisation : Lyon

Re: [NGINX + PHP-FPM] File not found

Message par benjarobin »

Voici une version corrigée de : /etc/nginx/sites-enabled/nimajneb.eu

Code : Tout sélectionner

server {
    server_name nimajneb.eu;
    root /srv/www/nimajneb.eu;

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

    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;
    }
}
J'ai juste copier-coller le Wiki.
Ton plus gros problème était le fait que la directive root n'était pas directement dans le bloc server.
Ce qui impliquait que SCRIPT_FILENAME n'était pas bon, et php ne trouvait pas le fichier
Zsh | KDE | PC fixe : core i7, carte nvidia
Titre d'un sujet : [Thème] Sujet (état) / Règles du forum
XunilunG
Hankyu
Messages : 11
Inscription : ven. 21 nov. 2014, 08:20

Re: [NGINX + PHP-FPM] File not found

Message par XunilunG »

Ca fonctionne parfaitement !
Je suis mitigé entre la honte et la joie... :(
Merci énormément pour ton aide, ton temps, ta réactivité... et tes explications benjarobin !! C'est vraiment encourageant pour l'autodidacte que je suis !
Je passe ce topic en résolu.

Merci encore.
Cordialement,
51peg_b
Répondre