网站首页 > 基础教程 正文
Nginx是大型架构的必备技能,今天就重点详解Nginx常用命令@mikechen
作者:mikechen
文章来源:mikechen.cc
Nginx版本
查看 Nginx 版本:
nginx -v
查看详细版本信息、与编译参数:
nginx -V
查找 Nginx 安装路径:
which nginx
Nginx服务
启动 Nginx:(默认读取 /etc/nginx/nginx.conf)
nginx
强制停止(立即关闭所有进程)
nginx -s stop
优雅停止(处理完当前连接后关闭)
nginx -s quit
平滑重载配置(不影响正在处理的请求)
nginx -s reload
检查配置文件语法是否正确
nginx -t
检查指定配置文件语法
nginx -t -c /etc/nginx/nginx.conf
使用 systemd 管理 Nginx(推荐)
systemctl restart nginxsystemctl status nginx
Nginx配置
使用指定配置文件启动 Nginx:
nginx -c /usr/local/nginx/conf/nginx.conf
查看 Nginx 进程状态(master、 和 worker):
ps aux | grep nginx
查看端口监听状态(如:80/443)
netstat -tlnp | grep nginx
手动向主进程发送重载信号:
kill -HUP $(cat /usr/local/nginx/logs/nginx.pid)
Nginx管理
实时查看访问日志:
tail -f /var/log/nginx/access.log
实时查看错误日志:
tail -f /var/log/nginx/error.log
cat /var/log/nginx/error.log | grep [关键字]
排查错误关键词:
cat error.log | grep timeout
Nginx性能
使用 Apache Bench 压测 Nginx(n次并发c个):
ab -n 1000 -c 100 http://localhost/
查看响应头,确认 Nginx 正常工作:
curl -I http://localhost
让 Nginx 以前台方式运行(容器中常用):
nginx -g "daemon off;"
查看80端口被哪个进程占用:
lsof -i :80
Nginx高级
nginx -V 2>&1 | grep --color -o http_stub_status_module
检查是否编译了某模块:
nginx -V 2>&1 | grep --color -o http_ssl_module
指定工作目录运行(含日志/临时目录。。。等):
nginx -p /custom/nginx/
nginx -g "pid /tmp/nginx.pid;"
临时覆盖配置项运行 Nginx:
nginx -g "pid /tmp/nginx.pid; worker_processes 4;"
Nginx命令
查找配置文件:
find / -name nginx.conf
在容器中测试配置,是否正确:
docker exec nginx-container nginx -t
测试正向代理是否生效
curl -x localhost:8888 https://mikechen.cc
以上
本篇已收于mikechen原创超30万字《阿里架构师进阶专题合集》里面。
猜你喜欢
- 2025-05-22 Linux cron任务计划
- 2025-05-22 测试人员如何在linux服务器中查询mysql日志?
- 2025-05-22 初识自动化网络编排器NSO,轻松配置复杂的多厂商网络
- 2025-05-22 Nacos在企业生产中如何使用集群环境?
- 2025-05-22 如何从 MySQL 错误日志中排查数据库故障
- 2025-05-22 Linux面试最高频的5个基本问题
- 2025-05-22 linux网卡混杂模式
- 2025-05-22 Linux环境下Java应用的部署与优化
- 2025-05-22 Linux系统网站出现503错误提示怎么解决?
- 2025-05-22 运维命令——查看日志journalctl详解
- 05-22Linux cron任务计划
- 05-22测试人员如何在linux服务器中查询mysql日志?
- 05-22Nginx命令最全详解(29个最常用命令)
- 05-22初识自动化网络编排器NSO,轻松配置复杂的多厂商网络
- 05-22Nacos在企业生产中如何使用集群环境?
- 05-22如何从 MySQL 错误日志中排查数据库故障
- 05-22Linux面试最高频的5个基本问题
- 05-22linux网卡混杂模式
- 最近发表
- 标签列表
-
- jsp (69)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- pythonif (86)
- location.href (69)
- dockerexec (65)
- tail-f (79)
- deletesql (62)
- c++模板 (62)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- console.table (62)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)