白色屏幕显示在ubuntu 16,php 7中的php文件,使用nginx

时间:2016-12-24 21:57:41

标签: php ubuntu nginx ubuntu-16.04 php-7

我正在尝试在我的服务器上运行php文件。它有Ubuntu 16.04.1 LTS(Xenial)和PHP 7.0.14-2 + deb.sury.org~xenial + 1。我一直在努力让这个工作,并在互联网上寻找到目前为止尚未奏效的解决方案。这是我的/ etc / nginx / sites-available / default文件:

server {
    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;
    listen 443 ssl;
    server_name myurl.com www.myurl.com

    ssl_certificate /some_file_path/...;
    ssl_certificate_key /some_file_path/...;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /some_file_path/...;

    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    location ~ /.well-known {
        allow all;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    #       include snippets/fastcgi-php.conf;
    #
    #       # With php7.0-cgi alone:
    #       fastcgi_pass 127.0.0.1:9000;
    #       # With php7.0-fpm:
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}
}

server {
    listen 80;
    server_name myurl.com www.myurl.com;
    return 301 https://$host$request_uri;
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }

我在想这个文件可能有问题。 php7.0-fpm确实存在于/ var / run / php /中,但它也存在于/ run / php中,我已经尝试了/var/run/php/php7.0-fpm.sock和/ run / php /php7.0-fpm.sock在显示fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;的行上,但也不起作用。我在每次更改后运行nginx -t后跟sudo service nginx restart,看它是否有效,但事实并非如此。

常规html文件有效,但php文件不起作用。我确实尝试了一段时间安装php5,看看我是否可以使用而不是php7(它默认安装,因为我使用的是ubuntu 16),但是当我这样做时似乎知道php5-fpm.sock文件(当我尝试时,我注意到了,

`ls /etc/php/5.6` showed `apache2    cli    mods-available`

但没有fpm目录

在哪里      ls /etc/php/7.0显示apache2 cli fpm mods-avaiable

现在,我实际上更喜欢让php 7工作,但是php 5将是最后的手段,但正如我上面所示,我在处理php5工作时已经死路一条,因为没有php5-fpm。 sock文件指向nginx配置文件,似乎php5-fpm似乎都缺失了。我想这是因为我发现如何在ubuntu 16上安装php5的指令是apache(但我不确定),并让我为此添加了一个存储库。但我正在使用nginx。我谈到的存储库是:ppa:ondrej / php。如果我无法获得php7工作是否存在php5-fpm与nginx和非apache的存储库?

注意:我刚刚尝试安装php7.1-fpm并更新了配置文件并重新启动了nginx,我仍然在php页面上显示白屏。

对此的任何帮助都将非常感激。

非常感谢。

1 个答案:

答案 0 :(得分:2)

我找到了答案。我必须将此行fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;添加到我的location php block

但在include fastcgi.conf;中使用location php block是更永久的解决方案。

对于遇到此问题的其他人,我会参考此链接: https://www.digitalocean.com/community/questions/website-displaying-blank-page-after-upgrading-ubuntu-server

ubuntu 16中这个nginx php 7问题的原因是根据ryanmortier"在更新之前,/ etc / nginx / fastcgi_params有一个SCRIPT_FILENAME参数。

然而,更新删除了该行并杀死了很多php-fpm网站。" (此引用来自本答复中发布的链接)。