0

So, I have a Nginx webserver nginx/1.18.0 on Debian 11.6. I also have php7.4-fpm.

Under /etc/nginx/sites-enabled/ I have two configs for two domains: domain1 and domain2. Both should be running Wordpress. First domain is running on HTTPS (and has a redirection from HTTP to HTTPS), the second should (for now) run just on HTTP.

The problem is, that first domain is working fine, however the second domain is not working. I mean, it is serving HTML files just fine, but when I try to access index.php file, it serves this file as a download (instead of executing).

So, some extended explanation of my environment:

First, php7.4-fpm is up and running (I left default settings, and as I said, domain1 is working just fine):

● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-01-11 11:26:32 CET; 2 days ago
       Docs: man:php-fpm7.4(8)
    Process: 503216 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
   Main PID: 503213 (php-fpm7.4)
     Status: "Processes active: 0, idle: 3, Requests: 1236, slow: 0, Traffic: 0.2req/sec"
      Tasks: 4 (limit: 1132)
     Memory: 424.1M
        CPU: 8min 11.672s
     CGroup: /system.slice/php7.4-fpm.service
             ├─503213 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             ├─508795 php-fpm: pool www
             ├─509933 php-fpm: pool www
             └─511244 php-fpm: pool www

Jan 11 11:26:32 cryptopia systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Jan 11 11:26:32 cryptopia systemd[1]: Started The PHP 7.4 FastCGI Process Manager.

Now config for domain1.conf:

server {
    listen 443 ssl http2; # managed by Certbot
    server_name domain1.mk www.domain1.mk;
    root /usr/share/nginx/html/domain1.mk;
    error_log /var/log/nginx/domain1_error.log;
    access_log /var/log/nginx/domain1_access.log;

    location / {
        index index.html index.htm index.php;
        expires -1;
        try_files $uri $uri/ /index.php?$args;
    }
 
    location ~ \.php$ {
       include /etc/nginx/fastcgi_params;
       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/domain1.mk$fastcgi_script_name;
    }

    ssl_certificate /etc/letsencrypt/live/domain1.mk/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain1.mk/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    keepalive_timeout 70;
    ssl_session_cache shared:TLS:10m;
    
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/letsencrypt/live/domain1.mk/chain.pem;
    resolver 127.0.0.1 [::1] valid=300s;
    resolver_timeout 10s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
    add_header X-Xss-Protection "1; mode=block" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin" always;
}

server {
    if ($host = www.domain1.mk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = domain1.mk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name domain1.mk www.domain1.mk;
}

And also config for domain2.conf:

server {
        listen 80;
        server_name domain2.test www.domain2.test; # for now I have this domain listed in my local /etc/hosts file
        root /usr/share/nginx/html/domain2.com;
        error_log /var/log/nginx/domain2_error.log;
        access_log /var/log/nginx/domain2_access.log;

        client_max_body_size 100M;

        location / {
                index index.html index.htm index.php;
                expires -1;
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
#                include snippets/fastcgi-php.conf;
#                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
#                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include /etc/nginx/fastcgi_params;
                 fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/domain2.com$fastcgi_script_name;
        }

}

I guess /etc/nginx/nginx.conf could also be of some interest:

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

events {
    worker_connections 768;
}

http {
    client_max_body_size 20m;
    sendfile on;
    tcp_nopush on;
    types_hash_max_size 2048;
    server_tokens off;

    server_names_hash_bucket_size 64;

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

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
        ssl_ciphers 'TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-256-GCM-SHA384:TLS13-AES-128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

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

Any idea what is wrong, so why Wordpress on domain1 is working just fine, but Wordpress on domain2 is not? (And yes, I restarted nginx server...)

I tried to check config, restarting php7.4-fpm and nginx, checked log files... I have no idea why this is behaving like this. I checked several similar questions and tried to change different parameters in php.ini as suggested, but those suggestions did not work in my case.

Matthai
  • 21
  • 1
  • Does this answer your question? [NginX not executing PHP](https://stackoverflow.com/questions/37305230/nginx-not-executing-php) – Salim Ibrohimi Jan 13 '23 at 11:06
  • No. I added ``` location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/domain2.com$fastcgi_script_name; } ``` But it is the same. – Matthai Jan 13 '23 at 18:04

0 Answers0