【问题标题】:WordPress download a file instead of opening in browserWordPress 下载文件而不是在浏览器中打开
【发布时间】:2021-09-29 16:33:00
【问题描述】:

我在我的服务器上使用 nginx 和 php-fpm7.2。当我尝试打开我的 WordPress 网站时,它不会加载,只是下载页面。我可以通过 url 访问除主页之外的所有其他页面。它发生在今天,我没有修改任何配置文件。 fastcgi 和同一台服务器上的其他站点正在运行。我尝试了任何我能找到的解决方案,但没有一个可以解决。 网站下载的文件如下

<?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';

这是我网站的配置文件

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;
    }

【问题讨论】:

    标签: wordpress nginx


    【解决方案1】:

    尝试添加类似的东西

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
    

    写在这里:https://dariuscoder.com/2021/09/29/wordpress-nginx-config/ 如果我删除这部分,我会得到相同的效果 - 它下载而不是执行。

    此外,如果它仍在下载 - 请确保您已重新启动 nginx 并清除浏览器缓存。在我清除缓存之前,即使 nginx 已停止,Chrome 仍在下载文件。

    【讨论】:

      猜你喜欢
      • 2011-11-08
      • 2019-03-08
      • 2013-10-25
      • 2016-12-14
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多