Score:0

Nginx - PHP never render. Html files work well

tr flag

when I enter PHP files, they load forever. But do not show up in the browser. After few minutes the browser goes to timeout.

Html files get shown/rendered correctly.

Here is my virtualhost:

server {
    listen 80;
    
        server_name localhost;

    root /var/www/site;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

And here are the most important things in the www.conf:

listen = /var/run/php/php7.2-fpm.sock
user = www-data
group = www-data

In php.ini I have:

cgi.fix_pathinfo=0

Of course I restarted php and nginx. I have no idea what's the problem

Versions:

nginx version: nginx/1.18.0 (Ubuntu)
PHP 7.2.34-36+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Oct 28 2022 18:25:54) ( NTS )

Can anyone please help?

Other data requested in the comments: nginx:conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;


#upstream php {
                #this should match value of "listen" directive in php-fpm pool
 #       server unix:var/run/php-fpm.so;
#       server 127.0.0.1:9000;
  #  }

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;



ls -la ../sites-available/
total 12
drwxr-xr-x 2 root root 4096 lis 30 22:02 .
drwxr-xr-x 8 root root 4096 lis 30 22:39 ..
-rw-r--r-- 1 root root  552 lis 30 22:02 site


ls -la ../sites-enabled/
total 8
drwxr-xr-x 2 root root 4096 lis 30 20:10 .
drwxr-xr-x 8 root root 4096 lis 30 22:39 ..
lrwxrwxrwx 1 root root   28 lis 30 18:17 site -> ../sites-available/site
Ginnungagap avatar
gu flag
Have you checked the nginx error logs?
tr flag
yes, nothing helpful. Only `signal process started` messages, when I restart the process. Nothing more.
Ginnungagap avatar
gu flag
Can you actually see the request you made which timed out in the logs or does it fail before reaching nginx?
tr flag
When I try to go to `/test.html` it appears in the logs `127.0.0.1 - - [30/Nov/2022:22:17:27 +0100] "GET /favicon.ico HTTP/1.1" 302 5 "http://localhost/test.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"`. However when I try to go to / it goes intop timeout and it doesn't appear nor in access.log nor in error.log
Ginnungagap avatar
gu flag
Can you post your full nginx configuration? You either have another error log or some other equipment between your client and nginx.
tr flag
added to the original topic @Ginnungagap
tr flag
I can add that if I try to go to specific php files, like `http://localhost/index.php` or `http://localhost/wp-admin` I get in the logs: `127.0.0.1 - - [30/Nov/2022:23:26:06 +0100] "GET /index.php HTTP/1.1" 200 6942 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"` - it takes very long to load the page and the page loads some text, but this text is broken, without styles. In console log I see similar: Failed to load resource: `net::ERR_CONNECTION_TIMED_OUT` for css, js, etc
us flag
Please don't use unsupported versions of software. PHP 7.2 support was ended in end of 2020, and you are risking your site with security issues. Also, please edit the original question and add log snippets there instead of adding to comments. The log snippets are more readable in the question.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.