在这个项目的本地开发时,我遇到了一些问题,当我的page应用程序抛出一个500错误时,我看到的是一个502 Bag Gateway,而不是一个由PHP呈现的错误页面。我确实设置了以下env:
APP_ENV=local
APP_DEBUG=true
APP_LOG_LEVEL=debug在prod中,我看到Laravel像预期的那样解析500.blade.php错误页面,但是本地没有显示任何内容。
例如,一个错误的方法调用可以触发以下操作:
022/09/04 22:19:45错误867#867:*103 FastCGI在stderr中发送:“local.ERROR消息: 2022-09-04 22:19:45 local.ERROR:调用未定义的方法.
我还无法识别在nginx中可以调整的任何配置设置,这将使它能够显示错误,而不是坏网关。
对于这里可能需要更改的配置有任何建议吗?
Nginx配置:
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name app;
access_log off;
error_log /dev/stdout;
root /var/www/html/public;
index index.php;
charset utf-8;
# this causes issues with Docker
sendfile off;
location = favicon.ico { log_not_found off; access_log off; }
location = robots.txt { access_log off; log_not_found off; }
# look for local files on the container before sending the request to fpm
location / {
try_files $uri /index.php?$query_string;
}
# nothing local, let fpm handle it
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
# Httpoxy exploit (https://httpoxy.org/) fix
fastcgi_param HTTP_PROXY "";
# allow larger POSTS for handling oauth tokens
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
# Deny .htaccess file access
location ~ /\.ht {
deny all;
}
}发布于 2022-09-07 08:19:43
我以这种方式创建了我的nginx nginx,它正在为我工作,我正在使用8000 port,但您可以使用80 port。但是,最好不要将端口80映射到本地开发中的任何单个项目,因为大多数情况下我们都在处理多个项目,因此您应该需要启用每个project的不同的ports。
server {
listen 8000;
root /var/www/html/<project-path>/public;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php/php7.4-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}我希望这会对你有帮助。
发布于 2022-09-08 18:07:58
我认为这种行为是由php配置引起的,而不是由nginx造成的。试着设置
display_errors = on;除非另有指示,否则nginx会传递它接收到的确切错误代码。
还有一个选择,我可以想到,也许脚本是由于某种原因导致502的错误超时。
发布于 2022-09-13 14:25:46
从您的请求中得到的实际标题响应是什么?
我建议您做一些测试,如果这是nginx配置、php配置或您的laravel环境和错误处理的问题,就尝试隔离这个问题。
您可以在公用文件夹中创建一个test.php文件。
即
<?php
http_response_code(500);
TEST;现在,如果您打开site/test.php,您是得到500个错误,还是502号错误?显示类似于未定义测试常量的错误。
或者,如果你编辑public/index.php并打破代码,比如在某个地方添加.,你是否也会在你的laravel应用程序中得到502的响应?
当您将nginx设置为代理或没有得到有效的响应时,通常会发生502错误,您可以启用调试模式来查看您的请求发生了什么。
同时发布你的nginx.conf
还可以尝试在php或主位置块上添加fastcgi_intercept_errors off;。
编辑
另一个可能的原因是上游太大,而且比您的nginx配置buffer_size还多。
您可以尝试增加缓冲区大小,
在http中添加whatever-environment-you-have/nginx/nginx.conf块
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;然后在~php块上添加以下内容
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;如果仍然不起作用,试着增加所有的4096k
https://stackoverflow.com/questions/73603204
复制相似问题