【发布时间】: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 时,它只是空白。文件在那里