Nginx常用命令

如果使用以下命令报错-bash: nginx: command not found请先将nginx的路径写进环境变量里

https://blog.csdn.net/weixin_42940307/article/details/139509243

启动nginx 停止nginx

# 停止 Nginx
sudo systemctl stop nginx
 
# 启动 Nginx
sudo systemctl start nginx

重启 Nginx

方法1:使用 systemctl(推荐)
sudo systemctl restart nginx

方法2:使用 service
sudo service nginx restart

方法3:使用 nginx 命令
sudo nginx -s reload

检查 Nginx 状态

# 检查 Nginx 是否正在运行
sudo systemctl status nginx
 
# 或使用
sudo service nginx status

 重新加载配置

sudo systemctl reload nginx

测试配置文件语法

sudo nginx -t

使用 whereis 命令查找 nginx 相关文件

whereis nginx

使用 find 命令在系统中搜索

# 从根目录开始搜索
sudo find / -name nginx
 
# 或者搜索配置文件
sudo find / -name nginx.conf

查看 Nginx 错误日志(如果遇到问题)

sudo tail -f /var/log/nginx/error.log

查看 Nginx 访问日志

sudo tail -f /var/log/nginx/access.log

查看nginx进程

# 查看 nginx 进程
ps -ef | grep nginx

查看 nginx 版本和编译信息

nginx -V

如果使用包管理器安装的,可以查看包信息

# 对于 Debian/Ubuntu 系统
dpkg -L nginx
 
# 对于 CentOS/RHEL 系统
rpm -ql nginx

 

posted @ 2025-07-10 13:24  江南大才子  阅读(22)  评论(0)    收藏  举报