最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】nginx重启出错:Stoping nginx emerg unknown directive in

出错 crifan 1284浏览 0评论
折腾:
【未解决】阿里云中二级域名转发中如何实现端口转发
期间,用加上nginx配置:
server
{
    listen 80;
    server_name 
dev.xxx;

    access_log  /www/wwwlogs/
dev.xxx.log;

    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_Header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    location /storybook/
    {
        # proxy_redirect off;
        # proxy_pass 
http://xxx:33800;
        proxy_pass 
http://xxx:33800/;
    }

}
结果重启nginx出错:
[root@xxx nginx]# systemctl status nginx
● nginx.service - LSB: starts the nginx web server
   Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
   Active: active (running) since Tue 2018-03-27 16:17:19 CST; 7 months 23 days ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/nginx.service
           ├─1237 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
           ├─1241 nginx: worker process
           ├─1243 nginx: worker process
           └─1244 nginx: cache manager process

Mar 27 16:17:18 
xxx
 systemd[1]: Starting LSB: starts the nginx web server...
Mar 27 16:17:19 
xxx
 nginx[873]: Starting nginx...  done
Mar 27 16:17:19 
xxx
 systemd[1]: Started LSB: starts the nginx web server.
[root@xxx nginx]# systemctl reload nginx
[root@xxx nginx]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@xxx nginx]# systemctl status nginx 
● nginx.service - LSB: starts the nginx web server
   Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2018-11-19 15:55:32 CST; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 4274 ExecStop=/etc/rc.d/init.d/nginx stop (code=exited, status=1/FAILURE)
  Process: 4260 ExecReload=/etc/rc.d/init.d/nginx reload (code=exited, status=0/SUCCESS)
  Process: 4282 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
   CGroup: /system.slice/nginx.service
           ├─1237 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
           ├─1241 nginx: worker process
           ├─1243 nginx: worker process
           └─1244 nginx: cache manager process

Nov 19 15:55:32 
xxx
 systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 19 15:55:32 
xxx
 systemd[1]: Unit nginx.service entered failed state.
Nov 19 15:55:32 
xxx
 systemd[1]: nginx.service failed.
Nov 19 15:55:32 
xxx
 systemd[1]: Starting LSB: starts the nginx web server...
Nov 19 15:55:32 
xxx
 nginx[4282]: Starting nginx... nginx (pid 1244 1243 1241 1237) already running.
Nov 19 15:55:32 
xxx
 systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 19 15:55:32 
xxx
 systemd[1]: Failed to start LSB: starts the nginx web server.
Nov 19 15:55:32 
xxx
 systemd[1]: Unit nginx.service entered failed state.
Nov 19 15:55:32 
xxx
 systemd[1]: nginx.service failed.
出错了,去找找原因
之前VSCode中,对于配置文件第10行就白色,不正常:
现在去通过:
[root@xxx nginx]# journalctl -xe
Nov 19 15:55:24 
xxx
 nginx[4260]: Reload service nginx... nginx: [emerg] unknown directive "proxy_set_Header" in /www/server/panel/vhost/nginx/
dev.xxx.conf:10
Nov 19 15:55:24 
xxx
 nginx[4260]: done
Nov 19 15:55:24 
xxx
 systemd[1]: Reloaded LSB: starts the nginx web server.
-- Subject: Unit nginx.service has finished reloading its configuration
-- Defined-By: systemd
-- Support: 
http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has finished reloading its configuration
-- 
-- The result is done.
Nov 19 15:55:24 
xxx
 polkitd[470]: Unregistered Authentication Agent for unix-process:4254:2047549400 (system bus name :1.80164, object path /org/freedesktop/PolicyKit1/Authent
Nov 19 15:55:32 
xxx
 polkitd[470]: Registered Authentication Agent for unix-process:4268:2047550185 (system bus name :1.80165 [/usr/bin/pkttyagent --notify-fd 5 --fallback], ob
Nov 19 15:55:32 
xxx
 systemd[1]: Stopping LSB: starts the nginx web server...
-- Subject: Unit nginx.service has begun shutting down
-- Defined-By: systemd
-- Support: 
http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has begun shutting down.
Nov 19 15:55:32 
xxx
 nginx[4274]: Stoping nginx... nginx: [emerg] unknown directive "proxy_set_Header" in /www/server/panel/vhost/nginx/
dev.xxx.conf:10
Nov 19 15:55:32 
xxx
 nginx[4274]: failed. Use force-quit
Nov 19 15:55:32 
xxx
 systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 19 15:55:32 
xxx
 systemd[1]: Unit nginx.service entered failed state.
Nov 19 15:55:32 
xxx
 systemd[1]: nginx.service failed.
Nov 19 15:55:32 
xxx
 systemd[1]: Starting LSB: starts the nginx web server...
看到错误原因是:
Stoping nginx… nginx: [emerg] unknown directive “proxy_set_Header” in /www/server/panel/vhost/nginx/dev.xxx.conf:10
才注意到是拷贝别人的配置,语法错误,写成大写H了:
proxy_set_Header X-Real-IP $remote_addr;
应该改为:
proxy_set_header X-Real-IP $remote_addr;
【总结】
此处不小心把配置中:
proxy_set_header X-Real-IP $remote_addr;
(从别人代码拷贝过来的)误写为:
proxy_set_Header X-Real-IP $remote_addr;
所以报错。改正后,即可解决问题。

转载请注明:在路上 » 【已解决】nginx重启出错:Stoping nginx emerg unknown directive in

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.209 seconds, using 22.16MB memory