Nginx服务器性能调优

Nginx 配置文件

1、根据CPU内核数设置worker进程个数,以12核CPU为例,设置11个worker进程:

worker_processes 11;

worker_cpu_affinity 000000000010 000000000100 000000001000 000000010000 000000100000 000001000000 000010000000 000100000000
001000000000 010000000000 100000000000;

2、事件模块

events {
worker_connections 65535;    # 单个worker进程的最大连接数
use epoll;
}

3、系统限制性参数

worker_rlimit_nofile 65535;    # 描述符最大限制

ulimit -a 命令可以查看当前系统的限制性参数;

在/etc/security/limits.conf 写入配置:

* soft nofile 65535

* hard nofile 65535

* soft nproc 65535

* hard nproc 65535

以上参数也可以写入 /etc/profile 文件使其生效。

4、其它

keepalive_timeout  60;     # 客户端长连接超时时间

tcp_nopush on;        #

user www-data;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile ;
events {
worker_connections ;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
access_log off;
error_log /var/log/nginx/error.log crit;
keepalive_timeout ;
client_header_timeout ;
client_body_timeout ;
reset_timedout_connection on;
send_timeout ;
limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr ;
include /etc/nginx/mime.types;
default_type text/html;
charset UTF-;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length ;
gzip_comp_level ;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
open_file_cache max= inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses ;
open_file_cache_errors on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

内核TCP选项

在/etc/sysctl.conf 写入配置:

net.ipv4.tcp_max_tw_buckets = 6000

设置timewait值

net.ipv4.ip_local_port_range = 1024 65000

设置允许系统打开的端口范围

net.ipv4.tcp_tw_recycle = 1

是否启用timewait快速回收

net.ipv4.tcp_tw_reuse = 1

允许将TIME-WAIT sockets 重新用于新的TCP连接

net.ipv4.tcp_syncookies = 1

SYN等待队列溢出时,使用Cookies来处理

net.ipv4.tcp_max_orphans = 262144

net.ipv4.tcp_max_syn_backlog = 262144

记录尚未收到的客户端确认信息的连接请求的最大值

net.ipv4.tcp_timestamps = 0

使用时间戳作为序列号

net.ipv4.tcp_synack_retries = 1

设置SYN重试的次数

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_fin_timeout =1

net.ipv4.tcp_keepalive_time = 30

net.core.somaxconn = 262144

listen函数的backlog默认会将内核参数net.core.somaxconn限制到128

net.core.netdev_max_backlog = 262144

修改完成后执行 sysctl -p 命令使其生效。

 参考文档:

http://ourjs.com/detail/5290c35850c832bd03000001

Nginx 服务器性能参数设置的更多相关文章

  1. Tomcat性能参数设置

    Tomcat性能参数设置 Tomcat性能参数设置 博客分类: Java LinuxTomcat网络应用多线程Socket 默认参数不适合生产环境使用,因此需要修改一些参数 1.修改启动时内存参数.并 ...

  2. nginx服务器绑定域名和设置根目录的方法

    nginx服务器绑定域名以及设置根目录非常方便,首先进入nginx安装目录,然后执行 vim conf/nginx.conf 打开nginx的配置文件,找到 server { ..... ..... ...

  3. Nginx 服务器性能Bug和性能优化方案(真实经历)

    一.遇到的问题 1.问题:本应该是3个ffmpeg ,但是怎么会有5个ffmpeg出现? 2.Lua脚本问题,一直写入日志,导致有大量的日志,这里的错误日志是直接写进nginx的error.log 日 ...

  4. Nginx服务器性能优化与安全配置实践指南

    转载自:https://www.bilibili.com/read/cv16151784?spm_id_from=333.999.0.0 1.引言 1.1 目的 为了更好的指导部署与测试艺术升系统ng ...

  5. nginx+php-fpm性能参数优化原则

    1.worker_processes 越大越好(一定数量后性能增加不明显)   2.worker_cpu_affinity 所有cpu平分worker_processes 要比每个worker_pro ...

  6. 五种常用web服务器jvm参数设置

     一.tomcat Tomcat默认可以使用的内存为128MB,在较大型的应用项目中,这点内存是不够的,需要调大.有以下几种方法可以选用:第一种方法:在配置文件中设置Windows下,在文件/bi ...

  7. Appium 自动化测试(7) -- Appium 服务器初始化参数设置

    Desired Capabilities Desired capabilities 是一些发送给 Appium 服务器的键值对集合 (比如 map 或 hash),告诉服务器我们想要启动什么类型的自动 ...

  8. Mysql Innodb 性能参数设置 https://www.rathishkumar.in/2017/01/how-to-allocate-innodb-buffer-pool-size-in-mysql.html

    参考原文: https://www.rathishkumar.in/2017/01/how-to-allocate-innodb-buffer-pool-size-in-mysql.html 查看系统 ...

  9. nginx服务器绑定域名和设置根目录

    首先进入nginx安装目录的配置目录conf,然后执行 vi conf/nginx.conf 打开nginx的配置文件,找到并修改红字部分 server { listen default_server ...

随机推荐

  1. SQL Server 阻止了对组件 'Ole Automation Procedures' 的 过程'sys.sp_OACreate' 的访问

    --开启 Ole Automation Procedures sp_configure ; GO RECONFIGURE; GO sp_configure ; GO RECONFIGURE; GO E ...

  2. Returns: range-based (not absolute) index within the current range

    /** * This method is for use with UI Table addRows buttons that require the * addition of multiple r ...

  3. webapi 获取请求参数

    //获取请求消息提数据 Stream stream = filterContext.Request.Content.ReadAsStreamAsync().Result; Encoding encod ...

  4. SQL语句的添加、删除、修改多种方法

    SQL语句的添加.删除.修改虽然有如下很多种方法,但在使用过程中还是不够用,不知是否有高手把更多灵活的使用方法贡献出来? 添加.删除.修改使用db.Execute(Sql)命令执行操作╔------- ...

  5. 信息安全系统设计基础实验五 20135210&20135218

    北京电子科技学院(BESTI) 实     验    报     告 课程:信息安全系统设计基础           班级: 1352 姓名:程涵,姬梦馨             学号:2013521 ...

  6. 如何构建JSON数据,JSON数据的格式,JSON数据的获取

    假设你是用$.getJSON();方法获取JSON数据$.getJSON(url,{"Action":"getStudent"},function(data){ ...

  7. [转]MySQL Explain详解

    在日常工作中,我们会有时会开慢查询去记录一些执行时间比较久的SQL语句,找出这些SQL语句并不意味着完事了,些时我们常常用到explain这个命令来查看一个这些SQL语句的执行计划,查看该SQL语句有 ...

  8. -webkit-overflow-scrolling:touch iosBug

    IOS8+  -webkit-overflow-scrolling:touch 会导致webview崩溃 解决方案 用js动态添加样式  比如: $("body").css(&qu ...

  9. redis学习笔记——(2)

    4.Redis中的string类型 String类型是最简单的类型,一个Key对应一个Value,String类型是二进制安全的.Redis的String可以包含任何数据,比如jpg图片或者序列化的对 ...

  10. c# winform 火狐浏览器 查看cookie

    c# winform 火狐浏览器 查看cookie Firefox的Cookie数据位于:%APPDATA%\Mozilla\Firefox\Profiles\ 目录中的xxx.default目录,名 ...