Nginx 笔记

Nginx

[root@localhost ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

yum install nginx -y
[root@localhost ~]# nginx -h
nginx version: nginx/1.16.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /etc/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration fil


nginx 配置
main:

1.work_processes number|auto

2.work_cpu_affinity auto[cpumask]
CPU MASK:00000001 -->0号cpu
00000010 -->1号cpu
10000000 -->8号cpu
work_cpu_affinity 0001 0010 0100 1000;

[root@localhost nginx]# ps axo pid,cmd,psr,nice |grep nginx
1411 nginx: master process nginx 1 0
1621 nginx: worker process 0 0
1622 nginx: worker process 1 0
2168 grep --color=auto nginx 1 0

3.worker_priority -20to20
4.worker_rlimit_nofile Number(<=65535)


events:

1.worker_connections 15240;
每个worker时程所能打开的最大并发连接数量
总最大并发:worker_processe * worker_connections

2.use method
指明并发连接请求的处理方法,默认自动选择最优方法
use epoll;
3.accept_mutex on|off (互斥)
on指由各个worker轮流处理新请求,off指每个新请求的到达都会通知(唤醒)所有的worker进程,但只有一个进程可以
处理,off-造成“惊群”,影响性能,

调试和定位
1.daemon on|off
是否以守护进程方式运行nignx
2.master_process on|off
是否以master/worker模型运行nginx,默认为on

http:

1.server {
listen 80;
server_name kanghaibin;
root /usr/local/share/nginx/web;
}

2.tcp_nodelany on|off

3.sendfile on|off
是否启用sendfileal 功能,在内核中封装报文直接发达 ,默认off

4.server_tokens on|off
是否响应报文的server首部显示nginx版本信息 默认是on

5.location

6.try_files

7.client_body_temp_path

8.limit_rate Number 单位bytes/second 限制响应给客户端的传输速率,0为无限制

9.limit_except GET { #除了192.168.1.0网段允许用GET以外的方法,其实网络只能用GET方法;
allow 192.168.1.0/24;
deny all;
}

10.dirctio SIZE|off #当文件大于等于给定大小时,同步写磁盘

11.open_file_cache off;

LRU 最近最少使用算法


12.stub_status
示例:location /status {
stub_status;
allow 192.168.1.0/24;
deny all;
}

压缩
1.gzip on|off
2.gzip_comp_level Number(1-9)
3.gzip_min_length Length; 启用压缩功能的响应报文大小阈值;


示例:
gzip on;
gzip_comp_level 6;
gzip_min_length 64;
gzip_proxide any;
gzip_types text/xml text/css application/javascript;
gzip_vary on;

posted @ 2019-06-27 19:17  冬日的温暖  阅读(132)  评论(0编辑  收藏  举报