首页 > 系统相关 >nginx keepalive 设置避免 服务器端大量time_wait 增加tcp 连接重用

nginx keepalive 设置避免 服务器端大量time_wait 增加tcp 连接重用

时间:2023-11-17 15:44:19浏览次数:32  
标签:http 服务器端 tcp nginx proxy timeout gzip log

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    client_max_body_size   300m;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    send_timeout 100;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;


}

 

server {
    listen      80;
    server_name  _;
    # 前端打包好的dist目录文件
    root /usr/share/nginx/html/;
    index index.html;
    gzip on;
    gzip_static on;     # 需要http_gzip_static_module 模块
    gzip_min_length 1k;
    gzip_comp_level 4;
    gzip_proxied any;
    gzip_types text/plain text/xml text/css;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    

    location ~* ^/(a_svc_path|b_svc_path) {
       proxy_pass http://xxxx;
       proxy_connect_timeout 600s;
       proxy_send_timeout 600s;
       proxy_read_timeout 600s;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto http;
    }
    
    # 避免端点安全问题
    if ($request_uri ~ "/abc"){
        return 403;
    }
    
    if ($request_uri ~ "/xx"){
             return 403;
         }
}

 

标签:http,服务器端,tcp,nginx,proxy,timeout,gzip,log
From: https://www.cnblogs.com/ruiy/p/17838908.html

相关文章

  • php nginx 出现504 Gateway Timeout
    先试试:ini_set('memory_limit','4096M');set_time_limit(0);情况一:由于nginx默认的fastcgi进程响应缓冲区太小造成这种情况下导致fastcgi进程被挂起,如果fastcgi服务队这个挂起处理不是很好的话,就可能提示“504GatewayTime-out”错误。情况一解决办法:默认的fastcgi进程响......
  • 掌握Linux:查看服务器端口号的实用指南
    当你管理一个Linux服务器时,了解服务器上正在运行的服务以及它们使用的端口是至关重要的。这可以帮助你确保服务正常运行,定位问题,以及提高服务器的安全性。在这篇博客文章中,我将向你介绍如何使用Linux命令来查看服务端口号。查看所有打开的端口要查看服务器上所有打开的端口,可以使......
  • 默认nginx.conf
     usernginx;worker_processesauto;error_log/var/log/nginx/error.lognotice;pid/var/run/nginx.pid;events{worker_connections1024;}http{include/etc/nginx/mime.types;default_typeapplication/octet-stream;log_formatmain'$remote_a......
  • 内网走nginx代理访问高德webapi2.0
    需求:客户的电脑都只能访问内,服务器可以访问外网,客户电脑使用的项目中用到了高德webapi2.0。10.200.31.45:32100是我们的web服务器。网上基本上都是对高德webapi1.4的配置方式,而web2.0有一些差别。1.前端修改高德地图的js应用如果是index.html引入,修改之前的应用:<script......
  • Ubuntu 22.04 LTS 安装最新稳定版本nginx、mysql5.7和php7.2
    Ubuntu22.04LTS安装最新稳定版本nginx、mysql5.7和php7.2全部apt-get安装,就是快,迅速。前提是需要在有网络环境的情况下哈!!操作系统版本:Ubuntu22.04LTS一、安装最新稳定版本的nginxapt-getupdate#查看默认安装的nginx版本(默认为1.18。有点老,我们安装最新稳定版本)apt......
  • TCP time_wait close_wait处理方法
    CLOSE_WAIT是服务器未能处理完,导致CLOSE_WAIT一直处于存在,导致服务器资源消耗主要的配置参数:TCP_KEEPIDLETCP_KEEPINTVLTCP_KEEPCNTTIME_WAIT是客户端一直等待服务器过程,迟迟未等待服务器的返回,导致客户端资源消耗主要的配置参数:tcp_tw_reuse  对应LWIP里的SO_REUSE......
  • TCP乱序产生的原因
    网络拥塞:当网络拥塞时,数据包可能会在传输过程中因为网络负载过重而延迟或丢失,导致乱序数据的产生。路由选择:路由选择可以使数据包在传输过程中经过不同路径,这也可能导致乱序数据的产生。分段重组:由于网络链路的限制,数据包可能会被分段发送,接收端需要对这些分......
  • nginx 日志备份
    ·1、编辑脚本backup.sh#!/bin/bash#进入备份目录cd/data/nginx/logs/#设置备份名字newAccessLog="access`date+%Y-%m-%d`.log"newErrorLog="error`date+%Y-%m-%d`.log"#拷贝日志文件,已经在配置文件设置日志文件存放在:/data/nginx/logs/下,如果没有修改日志路径的一般在:/u......
  • nginx 定时重启
    1、编写脚本nginx_restart.sh#!/bin/bashps-ef|grepnginx|grep-vgrep>/data/nginx/nginx_restart.txtfile=$(cat/data/nginx/nginx_restart.txt|grepprocess|grep-vnginx_restart|awk'{print$2}')file_num=`cat/data/nginx/nginx_restart.......
  • nginx 日志查询
    转载:https://www.jianshu.com/p/f105fb19dd0b1、根据访问IP统计UVawk'{print$1}'access.log|sort|uniq-c|wc-l2、统计访问URL统计PVawk'{print$7}'access.log|wc-l3、查询访问最频繁的URLawk'{print$7}'access.log|sort|uniq-c|sort-n-k1-r|m......