第一步
通过运行进程找到nginx路径

ps -aux | grep 'nginx'

也可以通过查看nginx配置文件位置,顺便找出nginx路径。

ls /usr/local/nginx*/conf/nginx.conf

第二步

修改profile

nano /etc/profile

在最后export那里重启一行加入

export PATH=$PATH:/usr/local/nginx/sbin

其中/usr/local/nginx/为第一步你查到的nginx的路径

第三步

ctrtl+x保存退出nano编辑,然后重新加载配置

source /etc/profile