I'm using nginx and php-fpm7.2 on my server. When I try to open my WordPress website, it won't load and just download the page. I can access all other pages except the homepage through url. It occurs today and I didn't modify any config files. The fastcgi and the other sites on the same server is working. I've tried any solutions I can find and none of it can solve. The file download by the website is below
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( 'WP_USE_THEMES', true );
/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
This is the config file of my website
server
{
listen 80;
#listen [::]:80;
server_name sur.net.cn ;
index index.php ;
root /home/wwwroot/sur.net.cn;
include rewrite/none.conf;
#error_page 404 /404.html;
include enable-php.conf;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name sur.net.cn ;
index index.php ;
root /home/wwwroot/sur.net.cn;
ssl_certificate /home/wwwroot/ssl/5176542_sur.net.cn.pem;
ssl_certificate_key /home/wwwroot/ssl/5176542_sur.net.cn.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include rewrite/none.conf;
#error_page 404 /404.html;
include enable-php.conf;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
Try adding something like
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
as written here: https://dariuscoder.com/2021/09/29/wordpress-nginx-config/ If I remove this part, I get same effect - it downloads instead of executing.
Also if it still downloads – make sure you have restarted nginx and clear browser cache. Chrome was downloading file even with stopped nginx until I cleared cache.