【问题标题】:Nginx not excuting phpNginx 不执行 php
【发布时间】:2019-08-21 05:38:45
【问题描述】:

我在几个网站上使用 Nginx。第一次使用它并不太高兴(Apache 在我的情况下无法工作)。我正在尝试将 PHP 用于需要它的新项目。我有 PHP 7.3 FPM。测试, phpinfo();确实有效,但是在添加这个项目(openCAD)时,index.php 似乎是空白的。

我尝试安装 MyBB 以查看它是否执行,但它根本没有执行,只是一个空白页。

这是我的 nginx 配置

server {

        root /var/www/mywebsite.com/;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name mywebsite.com www.mywebsite.com;



         location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



}server {
    if ($host = www.mywebsite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mywebsite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



    listen 80;
    listen [::]:80;


    server_name mywebsite.com www.mywebsite.com;
    return 404; # managed by Certbot




}



server {
    if ($host = www.appeal.mywebsite.com) {
        return 301 https://mywebsite.com/appeal;
    } # managed by Certbot


    if ($host = appeal.mywebsite.com) {
        return 301 https://mywebsite.com/appeal;
    } # managed by Certbot


    listen 80 ;
    listen [::]:80 ;
    server_name www.appeal.mywebsite.com appeal.mywebsite.com;
    return 404; # managed by Certbot




}

server {


    if ($host = www.cad.mywebsite.com) {
        return 301 https://mywebsite.com/cad;
    } # managed by Certbot


    if ($host = cad.mywebsite.com) {
        return 301 https://mywebsite.com/cad;
    } # managed by Certbot


    listen 80 ;
    listen [::]:80 ;
    server_name www.cad.mywebsite.com cad.mywebsite.com;
    return 404; # managed by Certbot




}


这是尝试访问 MyBB 的错误日志

2019/08/20 15:48:11 [error] 23516#23516: *71 FastCGI sent in stderr: "PHP message: PHP Warning:  require_once(/var/www/mywebsite.com/php/inc/init.php): failed to open stream: No such file or directory in /var/www/mywebsite.com/php/global.php on line 20PHP message: PHP Fatal error:  require_once(): Failed opening required '/var/www/mywebsite.com/php/inc/init.php' (include_path='.:/usr/share/php') in /var/www/mywebsite.com/php/global.php on line 20" while reading response header from upstream, client: 70.44.50.53, server: mywebsite.com, request: "GET /php/index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "mywebsite.com"

【问题讨论】:

  • 如果执行了phpinfo(),则说明nginx和php安装正常。从错误消息来看,您很可能对路径的解析方式或权限问题有疑问。您是否验证了/var/www/mywebsite.com/php/inc/init.php 存在?是否正确设置了文件权限?
  • 嗯,你看过第 20 行的/var/www/mywebsite.com/php/global.php 了吗?该文件存在吗?
  • 这就是正在发生的事情。我将它放在 /mywebsite.com 的子目录中,因为它只能通过子目录访问。当我转到那个目录时,它要我下载一个未知文件,但是当我在 URL 中指定 index.php 时,它只是空白。文件在那里

标签: php nginx fastcgi


【解决方案1】:

根据您的错误日志,mybb 正在尝试在 /var/www/mywebsite.com/php/ 中查找其文件,但您的 root 设置为 /var/www/mywebsite.com/。所以看起来你没有正确设置它。如果您保持root 不变,则需要确保mybb 的incadmin 等文件夹是/var/www/mywebsite.com/ 的子目录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    相关资源
    最近更新 更多