#yyds干货盘点#Nginx的核心配置

Posted 王华_linux

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#yyds干货盘点#Nginx的核心配置相关的知识,希望对你有一定的参考价值。

1.全局配置

1.1 CPU内核的绑定

[root@c7-147 ~]# lscpu |grep -i cpu
CPU op-mode(s):        32-bit, 64-bit
CPU(s):                4     # 添加CPU核的个数
On-line CPU(s) list:   0-3
CPU family:            6
Model name:            Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
CPU MHz:               2903.998
NUMA node0 CPU(s):     0-3
[root@c7-147 html]# ps -ef |grep nginx   #开启nginx
root       2586      1  0 03:02 ?        00:00:00 nginx: master process /apps/nginx/sbin/nginx
nginx      2587   2586  0 03:02 ?        00:00:00 nginx: worker process
root       3112   2242  0 05:42 pts/0    00:00:00 grep --color=auto nginx
# 
[root@c7-147 ~]# cat /apps/nginx/conf/nginx.conf
#user  nobody;
worker_processes  4;  #4个核同时安排
worker_cpu_affinity auto;  #自动排序
#重启nginx
[root@c7-147 ~]# systemctl restart nginx
#客服端发送请求
[root@localhost rc.d]# while true;do curl http://10.0.0.147/index.html;sleep 0.5; done
# 服务端查看是哪些CPU的核在发生变化情况
[root@c7-147 ~]# watch -n1 ps -axo pid,cmd,nice,psr | grep nginx

1.2 错误日志

[root@c7-147 ~]# ulimit -n
1024
[root@c7-147 ~]# ulimit -n 1048576  #最多打开这么多(2*20)
[root@c7-147 ~]# ulimit -n 1048577
-bash: ulimit: open files: cannot modify limit: Operation not permitted
[root@c7-147 ~]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.

1.3

[root@c7-147 ~]# grep master* /apps/nginx/conf/nginx.conf
master_process off;  #默认是on,关闭以后就只有一个主进程,性能很差
[root@c7-147 ~]# systemctl restart nginx
[root@c7-147 ~]# ps -ef |grep nginx   #开启以后都只有一个主进程了
root       6700      1  0 06:38 ?        00:00:00 /apps/nginx/sbin/nginx
root       6702   1334  0 06:38 pts/0    00:00:00 grep --color=auto nginx

1.4 httpd配置详解

以上是关于#yyds干货盘点#Nginx的核心配置的主要内容,如果未能解决你的问题,请参考以下文章

#yyds干货盘点#nginx配置

#yyds干货盘点#nginx代理配置

#yyds干货盘点#nginx配置反向代理

#yyds干货盘点#30个类手写Spring核心原理之AOP代码织入

#yyds干货盘点#Nginx配置SSL证书

Nginx最常用的七种模块配置 #yyds干货盘点#