在/usr/local/目录下安装了nginx,并将nginx/sbin加入PATH,却提示:command not found。
# 切换到root用户
$ vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin
$ source /etc/profile
$ which nginx
/usr/local/nginx/sbin/nginx
$ nginx -t #到这里是OK的
#切换到普通用户,比如test用户
$ nginx -t
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:2
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] open() "/vdb/logs/nginx/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
#从输出来看,这是权限不够原因。
$ sudo nginx -t
sudo nginx:commmand not found
#加上sudo又提示找不到此命令
#明明把nginx加入了PATH环境变量,为啥使用sudo,还找不到nginx这个命令了呢?
#经过一番苦苦思考与百度,发现只有在“/etc/sudoers”里面的secure_path指定目录下的命令才可以使用sudo。
$ cat /etc/sudoers
......
Defaults secure_path = /sbin