一、查看nginx实际调用的配置文件
1、locate
若安装了locate可通过该命令进行查看。
[root@xxx nginx]# locate nginx.conf
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.default
...
如果服务器中存在多个nginx.conf文件,我们并不知道实际上调用的是哪个配置文件,因此我们必须找到实际调用的配置文件才能进行修改。
2、ps查看可执行文件再确定配置文件
(1)先查看可执行文件
[root@xxx nginx]# ps aux|grep nginx
root 352 0.0 0.0 2468624 924 ?? S 10:43上午 0:00.08 nginx: worker process
root 232 0.0 0.0 2459408 532 ?? S 10:43上午 0:00.02 nginx: master process /usr/local/nginx/sbin/nginx -g daemon off;
root 2345 0.0 0.0 2432772 640 s000 S+ 1:01下午 0:00.00 grep nginx
(2)再通过可执行文件查看配置文件
[root@xxx nginx]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
若上面两种方式无法确认可执行文件位置,则可通过下面这种方式,基本无往不利。
3、通过端口查看进程,再通过进程查看可执行文件,最后确定配置文件位置
(1)查看nginx的PID,以常用的80端口为例。
[root@xxx nginx]# netstat -lntup|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 13309/nginx
#由此可知nginx进程号是13309
(2)通过相应的进程ID(比如:13309)查询当前运行的nginx路径。
[root@xxx nginx]# ll /proc/13309/exe
lrwxrwxrwx 1 root root 0 Jan 4 17:02 /proc/13309/exe -> /usr/local/nginx/sbin/nginx
(3)获取到nginx的执行路径后,使用-t参数即可获取该进程对应的配置文件路径。
[root@xxx nginx]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
二、重启nginx
1、GNU/Linux nginx重启
kill -HUP 进程号或进程号文件路径
或
可执行文件路径 -s reload
判断Nginx配置是否正确:
nginx -t -c /usr/nginx/conf/nginx.conf
或
/usr/nginx/sbin/nginx -t
2、Centos nginx重启
service nginx restart
/etc/init.d/nginx stop
/etc/init.d/nginx start
3、Ubuntu Nginx重启
$sudo service nginx start
$sudo service nginx stop