Nginx学习笔记
运行环境
1 | OS: Ubuntu 24.04 noble |
安装
1 | cd /usr/local/src |
配置文件位于 /usr/local/nginx/conf/nginx.conf
基本指令
- 启动、停止和重新加载配置
1 | nginx -s <signal> |
其中 signal 包括
stop— 快速关闭quit— 优雅关闭,也可以使用kill -s QUIT <PID>指令关闭 Nginx 服务
主进程的 ID 号位于
/usr/local/nginx/logs/nginx.pid
reload— 重新加载配置文件:一旦主进程收到重新加载配置的信号,它会检查新配置文件的语法有效性并尝试应用其中提供的配置。如果成功,主进程将启动新的工作进程,并向旧的工作进程发送消息,请求它们关闭。否则,主进程将回滚更改,并继续使用旧配置。旧的工作进程收到关闭命令后,将停止接受新连接,并继续处理当前请求,直到所有此类请求都得到处理。之后,旧的工作进程退出。
重新加载配置后,错误日志位于
/usr/local/nginx/logs/error.log
reopen— 重新打开日志文件
基本配置
静态服务
1 | worker_processes 1; |
代理服务
1 | worker_processes 1; |
源代码解读
1 | . |
graph LR
subgraph core["核心模块"]
direction LR
ngx_core["ngx_core"]
ngx_errlog["ngx_errlog"]
ngx_conf["ngx_conf"]
ngx_events["ngx_events"]
ngx_event["ngx_event"]
ngx_epoll["ngx_epoll"]
ngx_regex["ngx_regex"]
end
subgraph modules[" "]
direction LR
subgraph third["第三方模块"]
direction TB
Rds_json_nginx["Rds-json-nginx"]
Lua_nginx["Lua-nginx"]
Others4["Others"]
end
subgraph mail["邮件服务模块"]
direction TB
Ngx_mail_core["Ngx_mail_core"]
Ngx_mail_pop3["Ngx_mail_pop3"]
Others3["Others"]
end
subgraph http_opt["可选 HTTP 模块"]
direction TB
Ngx_http_gzip["Ngx_http_gzip"]
Ngx_http_ssl["Ngx_http_ssl"]
Others2["Others"]
end
subgraph http_std["标准 HTTP 模块"]
direction TB
Ngx_http_core["Ngx_http_core"]
Ngx_http_charset["Ngx_http_charset"]
Others1["Others"]
end
end
core ~~~ modules
参考资料
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 科海拾零!
评论