一、问题
由于工作需求xx云服务器上安装了两个nginx实例,突然有一天需要在非默认nginx上增加一个子站点,根据网上教程和原来的记录修改vi nginx.conf 后保存载总也不生效?
怎么破?
二、过程记录
假如:非默认nginx安装在 /usr/local/nginx
那么我 第一步:cd 到/usr/local/nginx
第二步:nginx -s reload
第三步:sbin/nginx -c conf/nginx.conf
理论上是没有错的,初始没有任务效果
三、解决要点
我们始终要头脑清醒,不管当前在什么目录,默认命令肯定是招待默认实例
即便当前目标是 非默认实例nginx路径,如果不指定路径,直接键入 nginx命令依然指向默认实例
所以:
假如:非默认nginx安装在 /usr/local/nginx
那么我 第一步:cd 到/usr/local/nginx
第二步: ./nginx -s reload
第三步:sbin/nginx -c conf/nginx.conf
指定相对路径nginx路径配置生效:
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx/sbin# ./nginx -s reload
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx# sbin/nginx -c conf/nginx.conf
--------------------------------
ot@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx/sbin# nginx -s reload
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx/sbin# ./nginx -s reload
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx/sbin# ./nginx -c ./conf/nginx.conf
nginx: [emerg] mkdir() "./html/hls" failed (2: No such file or directory)
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx/sbin# ./nginx -c ../conf/nginx.conf
nginx: [emerg] open() "/usr/local/nginx/../conf/nginx.conf" failed (2: No such file or directory)
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx/sbin# cd ../
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx# sgin/nginx -c conf/nginx.conf
-bash: sgin/nginx: No such file or directory
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx# sbin/nginx -c conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1110 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1111 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1112 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1113 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1114 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1115 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1116 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1117 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1118 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1119 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8022 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1110 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1111 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1112 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1113 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1114 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1115 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1116 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1117 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1118 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1119 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8022 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1110 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1111 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1112 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1113 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1114 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1115 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1116 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1117 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1118 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1119 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8022 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1110 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1111 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1112 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1113 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1114 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1115 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1116 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1117 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1118 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1119 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8022 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1110 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1111 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1112 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1113 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1114 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1115 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1116 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1117 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1118 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1119 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8022 failed (98: Address already in use)
nginx: [emerg] still could not bind()
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx# telnet 127.0.0.1 1116
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
root@iZuf644aq2mn3ba0k4ain8Z:/usr/local/nginx#
要点是 第二步 “./”
第二步: ./nginx -s reload
只有增加"./" 才是指向实际 指定路径的 nginx 只要不加 “./” 或类似等同的路径限定符,都是默认nginx实例 nginx -s reload 兄弟们就是执行N次都是依然不生效
四、总结
多nginx实例 时要点是 除了 默认实例外,始终要有路径限定符的概念,不可大意,不要迷糊,在此备忘,同时希望可以帮到兄弟们!不是能力问题,是实践问题!
五、拓展
同理,我们默认控制nginx 开,关,状态查询命令,如下命令,如果不指定路径限定符,始终是默认实例状态,开,停,而不是非默认实例,
systemctl status nginx
systemctl start nginx
systemctl stop nginx
我们即要习惯默认实例的常用 命令,也要适应多个实例,非默认实例的路径限定关系
正常的步骤应当是
cd 到/usr/local/nginx
systemctl status ./nginx
systemctl start ./nginx
systemctl stop ./nginx