gpt4 book ai didi

php - 使用 nginx 在 ubuntu 16、php 7 中显示 php 文件的白屏

转载 作者:行者123 更新时间:2023-12-04 18:30:04 25 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












我们不允许在 Stack Overflow 上提出有关专业服务器或网络相关基础设施管理的问题。您可以编辑问题,使其成为 on-topic对于堆栈溢出。


5年前关闭。







Improve this question




我正在尝试让 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 页面上出现白屏。

对此的任何帮助将不胜感激。

非常感谢。

最佳答案

我找到了答案。我必须添加这一行: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 站点。”(此引用摘自此答案中发布的链接)。

关于php - 使用 nginx 在 ubuntu 16、php 7 中显示 php 文件的白屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41317122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com