跳转到主要内容

群晖的默认配置下,php的fastcgi处理超时时间只有60秒,当处理超时的时候就会报504错误(upstream timed out (110: Connection timed out) while reading response header from upstream...),而当vhost没有设置伪静态的时候,则会报405错误。知道问题所在处理起来就比较简单了。

处理405错误

这个其实是伪静态没有设置导致,当网站使用了伪静态的时候,访问这种url就会报错,处理方法就是在配置文件中添加。由于群晖(Synology)的webstation使用了配置模板(模板文件在/usr/syno/share/nginx/nginx.mustache),每次重启nginx服务的时候,都会刷新配置文件,所以人工手动修改vhost配置是无效的,synoservice --restart nginx 之后就按照模板设置复原了。修改这个模板文件可以永久改变nginx.conf文件配置。

当使用webstation创建一个vhost的时候,会在/etc/nginx/conf.d目录生成一个类似65577db7-9195-40ec-88a3-8abdc70e9dcd这种名称的目录,通过/etc/nginx/app.d/server.webstation-vhost.conf可以发现,这个目录下面user.conf*文件会被include到server{}配置中,所以可以在/etc/nginx/conf.d/65577db7-9195-40ec-88a3-8abdc70e9dcd下面创建一个user.conf配置的片段来实现伪静态。

if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
        rewrite (.*) /index.php;
}

这样就可以避免伪静态路径导致的405错误了。

处理504错误

这个错误通常是fastcgi的默认处理时间只有60秒导致,当请求处理超过60秒时则抛出(upstream timed out (110: Connection timed out)这个错误,可以通过/var/log/nginx/error.log查看。所有牵涉到nginx配置的问题,都可以通过在user.conf文件中进行配置来覆盖默认配置。

#通常设置600,不够再加大
fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
send_timeout 600s;

完成以上配置后,synoservice --restart nginx来重启服务,配置即可生效。查看nginx配置:nginx -T

通过以上设置,一般来说就不会再报405和504错误了。

分类