NGINX相关配置

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

NGINX相关配置

NGINX配置信息

nginx 官方帮助文档http://nginx.org/en/docs/

Nginx的配置文件的组成部分
主配置文件/conf/nginx.conf(/nginx/conf/nginx.conf)
子配置文件: include conf.d/*.conf

在这里插入图片描述


#事件驱动相关的配置   同步
event {
worker_connections 1024; #一次允许1024个执行
 ...
} 

#http/https 协议相关配置段
http {
server{
location{}
}
 ...
}

#默认配置文件不包括下面两个块
#mail 协议相关配置段
mail {
 ...
}

#stream 服务器相关配置段
stream {负载均衡
 ...
}

修改启动进程数

lscpu |grep -i cpu  #查看cup核数
[root@localhost ~]vim /apps/nginx/conf/nginx.conf
#开启 两核
#user  nobody;
worker_processes  4;  #根据CPU核数修改
worker_processes auto;  #如果设置为auto  就是你真实的cpu数量

在这里插入图片描述

关闭或修改版本

关闭版本
vim /apps/nginx/conf/nginx.conf
#修改配置文件  放在   http语句中
http {
    server_tokens  off; 
    }

nginx -s reload

修改版本
#在安装包中
[root@localhost core] vim /opt/nginx-1.18.0/src/core/nginx.h
#define NGINX_VERSION      "9527"
#define NGINX_VER          "http/" NGINX_VERSION

[root@localhost core] vim /opt/nginx-1.18.0/src/http/ngx_http_header_filter_module.c 
static u_char ngx_http_server_string[] = "Server: beijing " CRLF;

[root@localhost nginx-1.18.0]./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost nginx-1.18.0]make && make install

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

修改pid文件路径

mkdir /apps/nginx/run/ #创建目录
vim /apps/nginx/conf/nginx.conf #修改配置文件
pid   /apps/nginx/run/nginx.pid; #找到 pid的位置修改 
[root@localhost ~]#nginx -s reload 

CPU与work进程绑定

默认Nginx是不进行进程绑定的但是绑定了以后可以可以保证此进程不会运行在其他核心上这就极大减少了nginx的工作进程在不同的cpu核心上的来回跳转减少了CPU对进程的资源分配与回收以及内存管理等因此可以有效的提升nginx服务器的性能。

CPU序号
CPU MASK: 000000010号CPU
          000000101号CPU
          ................
  		  100000007号CPU

ps axo pid,cmd,psr,ni|grep -v grep |grep nginx|sort -n  #这个命令可以查看每个进程占用的是那个CPU
[root@localhost ~]vim /apps/nginx/conf/nginx.conf
worker_cpu_affinity 00000001 00000010 00000100 00001000;
[root@localhost ~]nginx -s reload 

在这里插入图片描述

进程的优先级

nice的优先级范围是-20~19

[root@localhost ~] ps axo pid,cmd,psr,ni|grep nginx|sort -n #查看优先级
[root@localhost ~]vim /apps/nginx/conf/nginx.conf
worker_priority -20; #将优先级调为-20
[root@localhost ~]nginx -s reload 

在这里插入图片描述
在这里插入图片描述

调试work进程打开的文件个数

[root@localhost ~]vim /apps/nginx/conf/nginx.conf
worker_rlimit_nofile 65536; #一次允许65536访问
events {
    worker_connections  20000;  #最大连接数
}
[root@localhost security]#nginx -s reload

临时修改
[root@localhost ~]#ulimit -n 60000  #只修改当前窗口
永久修改
[root@localhost security]#vim /etc/security/limits.conf #将下面内容直接写在文件末尾
*                soft    core            unlimited
*                hard    core            unlimited
*                soft    nproc           1000000
*                hard    nproc           1000000
*                soft    nofile          1000000
*                hard    nofile          1000000
*                soft    memlock         32000
*                hard    memlock         32000
*                soft    msgqueue        8192000
*                hard    msgqueue        8192000

永久修改后需要重启reboot才能生效临时的不用重启

[root@localhost security]ulimit -a #可以查看

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

服务前后台运行

一般都是后台运行前台运行容器中会用到
[root@localhost ~]vim /apps/nginx/conf/nginx.conf
daemon off;  #关闭后台运行
root@localhost security]nginx -s reload
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: nginx