nginx 的编译安装及基本操作
下载nginx
1 2 3 4 5 6 7 8 9 10 11 | [root@nginx ~] # wget http://nginx.org/download/nginx-1.14.0.tar.gz --2019-05-02 21:52:23-- http: //nginx .org /download/nginx-1 .14.0. tar .gz 正在解析主机 nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3 正在连接 nginx.org (nginx.org)|95.211.80.227|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:1016272 (992K) [application /octet-stream ] 正在保存至: “nginx-1.14.0. tar .gz” 100%[=====================================================================================================================================================>] 1,016,272 74.5KB /s 用时 13s 2019-05-02 21:52:43 (74.0 KB /s ) - 已保存 “nginx-1.14.0. tar .gz” [1016272 /1016272 ]) |
创建系统目录用户解压编译安装
1 2 3 4 5 6 7 | [root@nginx ~] # useradd -r nginx [root@nginx ~] # mkdir /etc/nginx [root@nginx ~] # mkdir /data/web [root@nginx ~] # tar xf nginx-1.14.0.tar.gz [root@nginx ~] # cd nginx-1.14.0 [root@nginx nginx-1.14.0] # ./configure --prefix=/data/web --user=nginx --group=nginx --sbin-path=/usr/bin --conf-path=/etc/nginx [root@nginx nginx-1.14.0] # make && make install |
拷贝contrib/vim/*的文件到~/.vim目录下
1 2 | [root@nginx nginx-1.14.0] # mkdir ~/.vim [root@nginx nginx-1.14.0] # cp -r contrib/vim/* ~/.vim/ |
编译时参数介绍
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | [root@nginx nginx-1.14.0] # ./configure --help | more --help print this message --prefix=PATH set installation prefix 安装目录 --sbin-path=PATH set nginx binary pathname 可执行文件目录 --modules-path=PATH set modules path 依赖模块目录 --conf-path=PATH set nginx.conf pathname 配置文件目录 --error-log-path=PATH set error log pathname 错误日志目录 --pid-path=PATH set nginx.pid pathname pid文件目录 --lock-path=PATH set nginx.lock pathname 日志目录文件 --user=USER set non-privileged user for 运行的用户 worker processes --group=GROUP set non-privileged group for 运行的组 worker processes --build=NAME set build name --builddir=DIR set build directory --with-select_module enable select module --without-select_module disable select module --with-poll_module enable poll module --without-poll_module disable poll module --with-threads enable thread pool support --with- file -aio enable file AIO support --with-http_ssl_module enable ngx_http_ssl_module --with-http_v2_module enable ngx_http_v2_module --with-http_realip_module enable ngx_http_realip_module |
如果要升级
1 2 3 | [root@nginx nginx-1.14.0] # ./configure --prefix=/data/web --user=nginx --group=nginx --sbin-path=/usr/bin --conf-path=/etc/nginx [root@nginx nginx-1.14.0] # make [root@nginx objs] # cp -a nginx /usr/bin 注意不可执行make install,把二进制文件复制过去 |
nginx配置语法
1.配置文件由指令与指令块构成
2.每条指令以;分号结尾,指令与参数之间空格隔开
3.指令块以{}大括号将多条指令组合在一起
4.include语句允许组合多个配置文件以提升可维护性
5.使用#添加注释,提高可读性
6.使用$符号使用变量
7.部分指令参数支持正则表达式
时间单位的表达
ms 毫秒 s 秒 m 分钟 h 小时 d 天 w 周 M 月 y 年
空间单位
什么也不加表示字节 k/K 表示千字节 m/M 表示兆字节 g/G 表示G字节
nginx 命令行格式介绍
1 2 3 4 5 6 7 | [root@nginx objs] # nginx -? -?或者-h 显示帮助 -c 指定配置文件;默认读取编译时指定路径下的配置文件 -g 指定配置指令;可以覆盖配置文件里的配置指令 -p 指定运行目录 -s 发送信号;stop:立刻停止 quit:优雅停止服务 reload:重载配置文件 reopen :重新记录日志文件 -t 检查配置文件语法是否错误 - v 打印版本 |
nginx的热部署
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@nginx ~] # cd nginx-1.15.12 [root@nginx nginx-1.15.12] # ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src [root@nginx nginx-1.15.12] # ./configure --prefix=/data/web --user=nginx --group=nginx --sbin-path=/usr/bin [root@nginx nginx-1.15.12] # make [root@nginx nginx-1.15.12] # mv /usr/bin/nginx{,.bak} [root@nginx nginx-1.15.12] # cp objs/nginx /usr/bin/ [root@nginx ~] # ps -aux | grep nginx | grep root 查出nginx主进程的pid号 root 40343 0.0 0.1 20544 1348 ? Ss 23:19 0:00 nginx: master process nginx [root@nginx ~] # kill -USR2 40343 向这个进程发送我要升级信号 [root@nginx ~] # ps -ef | grep nginx 升级完成 root 40343 1 0 23:19 ? 00:00:00 nginx: master process nginx nginx 40354 40343 0 23:26 ? 00:00:00 nginx: worker process root 42899 13537 0 23:42 pts /1 00:00:00 grep --color=auto nginx [root@nginx ~] # kill -WINCH 40343 向主进程发送优雅关闭工作进程的信号 |
草都可以从石头缝隙中长出来更可况你呢
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏