0 nginx工作原理:
Nginx里有一个master进程和多个worker进程,master进程并不处理网络请求,主要负责调度工作进程:加载配置,启动工作进程以及非停升级,worker进程负责处理网络请求与响应:
1 编译nginx-1.22.0
首先保证服务器有 nginx,本次对源码nginx-1.22.0.tar.gz 包,解压并进行编译,安装。
上传nginx-1.22.0.tar.gz到/app下,进行解压,编译如下
scp nginx-1.22.0.tar.gz @20.198.*.*/app
tar -zxvf nginx-1.22.0.tar.gz
1.1 新建 nginx目录,
在/app目录下新建nginx用户编译后nginx文件存放位置
[test@testapp1 ~]$ mkdir nginx
1.2 在nginx-1.22.0/下进行configure 配置
[test@testapp1 ~]$ cd nginx-1.22.0/
[test@testapp1 nginx-1.22.0]$ ./configure --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-debug
1.3 对nginx-1.22.0进行编译
[test@testapp1 ~]$ cd nginx-1.22.0/
[test@testapp1 nginx-1.22.0]$ make
[test@testapp1 nginx-1.22.0]$ make install
2 测试nginx安装是否成功
[test@testapp1 ~]$ cd /app/nginx
[test@testapp1 nginx]$ cd sbin/
[test@testapp1 sbin]$ ./nginx -V
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.1.1k FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/home/test/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-debug
3 修改nginx nginx.conf文件
备份原有配置文件
[test@testapp1conf]$ cd /app/nginx/conf
[test@testapp1conf]$ cp /app/nginx/conf/nginx.conf /app/nginx/conf/nginx_bak.conf
[test@testapp1 conf]$ vi nginx.conf
只是nginx服务的话,只需要修改标记的部分
listen nginx的服务端口
Server_name 如果只是nginx服务的话,填写nginx所在机器的ip就行
4 验证配置文件是否正确
[test@testes2 sbin]$ cd /app/nginx/sbin
[test@testes2 sbin]$ ./nginx -t
显示如下,则表明配置文件正确:
nginx: the configuration file /app/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx/conf/nginx.conf test is successful
5 启动nginx
[test@testapp1 ~]$ cd nginx
[test@testapp1 nginx]$ cd sbin/
[test@testpfpj sbin]$ ./nginx -c /app/nginx/conf/nginx.conf
检查nginx服务是否启动
[test@testpfpj sbin]$ ps -ef|grep nginx
test 50223 1 0 21:21 ? 00:00:00 nginx: master process ./nginx
test 50224 50223 0 21:21 ? 00:00:00 nginx: worker process
test 50226 28368 0 21:21 pts/0 00:00:00 grep --color=auto nginx
6 停止服务
有两种方式:
第一种方式:./nginx -s quit
第二种方式:./nginx -s stop
第三种方式:
先查看进程号[test@testpfpj sbin]$ ps -ef |grep nginx
在 Kill -QUIT 进程号
[test@testpfpj sbin]$ kill -QUIT 45988
查看nginx端口:ps aux|grep nginx