美文网首页
【nginx】 错误总结

【nginx】 错误总结

作者: miniy_7 | 来源:发表于2019-12-23 15:12 被阅读0次
  • upstream timed out (110: Connection timed out) while reading response header from upstream, client: 58.16.136.58, server: localhost, request: "POST /web/login/updateToken HTTP/1.1" ...
    答:根据问题分析,是由于nginx代理获取上游服务器返回超时照成,解决办法有两中一种是配置nginx超时时间,一种是根据错误信息定位超时接口进行优化。
    配置超时时间修改配置文件/conf/nginx.conf在 http,server,location 三个位置任意一个位置增加proxy_read_timeout参数,默认60s。该指令是指从上游服务器两次成功的读操作耗时的超时时间,也就意味着从上游服务器成功读操作后,过了60S,没有再从上游服务器成功读操作的话,就会关闭该连接。
proxy_read_timeout 300s;
  • 高并发下出现socket() failed (24: Too many open files) while connecting to upstream, client: 10..., server: localhost, request: "POST uri... HTTP/1.1", upstream: "...", host: "...", referrer: "..."
    答:高并发下nginx出现打开文件失败问题,我们可以设置单进程允许打开的文件数量限制,修改配置文件。
//worker_processes number|auto;可以设置成auto,也可设置1到cpu个数或核数,不要超过cpu核数
worker_processes 4; 
// 进程的最大打开文件数限制
worker_rlimit_nofile 65535;
//可设置到65536
worker_connections 10240; 

Linux中输入ulimit -a查看系统允许打开的最大文件数,太小可以更改;

image.png
  • no live upstreams while connecting to upstream
    答: 字面意思是nginx发现没有存活的后端server。增加keepalive参数配置,官网参数含义

Activates the cache for connections to upstream servers.
The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.
It should be particularly noted that the keepalive directive does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.
激活缓存以连接到上游服务器。
connections参数设置每个工作进程的缓存中保留的与上游服务器的空闲保持连接的最大数量。 如果超过此数量,则关闭最近最少使用的连接。
特别要注意的是,keepalive指令并不限制nginx worker进程可以打开的与上游服务器的连接总数。 connections参数应设置为足够小的数字,以允许上游服务器也处理新的传入连接。
用法:

upstream http_backend {
    server 127.0.0.1:8080;

    keepalive 16;
}

server {
    ...
    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        ...
    }
}
  • open() "/usr/local/nginx/html/favicon.ico" failed
    答: 找不到网站的logo,两种办法一种是在目录下放入logo,让服务器可以找得到。另外可以采取关闭此日志;
        location = /favicon.ico{
            log_not_found off;
            access_log off;
        }

相关文章

网友评论

      本文标题:【nginx】 错误总结

      本文链接:https://www.haomeiwen.com/subject/clmznctx.html