本地主机上的示例PHP页面显示空白页面

时间:2018-07-12 09:08:45

标签: php wordpress nginx

我遵循this guide在Linux计算机上设置示例WordPress网站。软件包已更改为较新的php7.2-gdphp7.2-curllibssh2-php。我的/etc/nginx/sites-available/davewordpress文件如下:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/wordpress;
    index index.php index.html index.htm;
    server_name localhost;

    location / {
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

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

davewordpress中创建/etc/nginx/sites-enabled链接并重新启动nginxphp7.2-fpm之后,我的localhost会显示空白页。我做错了什么?

1 个答案:

答案 0 :(得分:0)

好吧,我在寻找解决方案时遇到了this link,这确实可以帮助我们指向location ~ \.php$块。我注释了两行,并使其起作用。现在,该块看起来像这样:

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

第一行使用sudo nginx -t报告此问题:

"try_files" directive is duplicate in /etc/nginx/snippets/fastcgi-php.conf:5

第二行报告此问题:

"fastcgi_index" directive is duplicate in /etc/nginx/sites-enabled/u1804wordpress:27

很高兴终于弄明白了。我了解第一个错误。但是,有人可以向我解释第二个吗?