相关代码
https://github.com/masterzcw/nginx/tree/master/0801
Nginx的主要功能
- Nginx启动后, 会产生一个主进程, 主进程执行一系列的工作后会产生一个或者多个工作进程
- 在客户端请求动态站点的过程中, Nginx服务器还涉及和后端服务器的通信.
Nginx将接收到的Web请求通过代理转发到后端服务器, 由后端服务器进行数据处理和组织. - Nginx为了提高对请求的响应效率, 降低网络压力, 采用了缓存机制, 将历史应答数据缓存到本地。
可以用如下命令查看进程, 在主进程结束之前
$ pstree -apn|grep pcntl
压测
$ ab -n 10000 -c 100 -k http://127.0.0.1:9005/index.php
查看编译安装时的选项
$ .configure --help
nginx快速编译安装
# yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
# wget http://nginx.org/download/nginx-1.14.1.tar.gz
# tar -zxvf nginx-1.14.1.tar.gz
# ./configure --prefix=/usr/local/nginx\
--with-http_stub_status_module\
--with-http_gzip_static_module\
--with-http_realip_module\
--with-http_sub_module \
--with-http_ssl_module\
--with-http_realip_module \
--with-http_sub_module \
--with-http_gunzip_module\
--with-http_gzip_static_module\
--with-http_auth_request_module\
--with-http_random_index_module\
--with-http_slice_module\
--with-http_stub_status_module
# make && make install
nginx常用命令
查看Nginx的版本号:
nginx -V
停止
nginx -s stop
退出
nginx -s quit
重启加载配置
nginx -s reload
配置文件启动
nginx -c </path/to/config> # 为 Nginx 指定一个配置文件,来代替缺省的
测试配置文件
nginx -t 不运行,而仅仅测试配置文件. nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
查看进程
# netstat -apn|grep 80
查看信号编码
# kill -l
一部分信号
SIGHUP 终止进程 终端线路挂断
SIGINT 终止进程 中断进程
SIGIOT 建立CORE文件 执行I/O自陷
SIGKILL 终止进程 杀死进程
SIGPIPE 终止进程 向一个没有读进程的管道写数据
SIGALARM 终止进程 计时器到时
SIGTERM 终止进程 软件终止信号
SIGSTOP 停止进程 非终端来的停止信号
SIGTSTP 停止进程 终端来的停止信号
SIGCONT 忽略信号 继续执行一个停止的进程
SIGURG 忽略信号 I/O紧急信号
SIGIOT 忽略信号 描述符上可以进行I/O
SIGPROF 终止进程 统计分布图用计时器到时
SIGUSR1 终止进程 用户定义信号1
SIGUSR2 终止进程 用户定义信号2
SIGVTALRM 终止进程 虚拟计时器到时
nginx文档
https://www.nginx.cn/doc/