正在验证nginx conf文件
我试图使用nginx验证其conf文件,但我看到一些奇怪的错误:正在验证nginx conf文件,nginx,Nginx,我试图使用nginx验证其conf文件,但我看到一些奇怪的错误: $ nginx -t -c `pwd`/foo.conf ; echo $? nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) nginx: the configuration file /home/ubuntu/foo.conf syntax is ok 2
$ nginx -t -c `pwd`/foo.conf ; echo $?
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
nginx: the configuration file /home/ubuntu/foo.conf syntax is ok
2015/03/24 01:13:08 [emerg] 8464#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /home/ubuntu/foo.conf test failed
1
尽管这样做有效,但仍会打印错误消息:
$ nginx -t -c `pwd`/foo.conf -s stop ; echo $?
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
nginx: the configuration file /home/ubuntu/foo.conf syntax is ok
nginx: configuration file /home/ubuntu/foo.conf test is successful
0
正在传递-g'error\u log/tmp/error.log;'代码>似乎没有效果
这是conf文件:
events {}
http{
proxy_set_header Host $http_host;
server {
listen 80;
server_name localhost;
location /ui {
proxy_pass http://127.0.0.1:8000/ui;
}
}
}
我记得,nginx——至少是使用tarball并运行makeinstall的默认安装——没有创建日志目录(/var/log/nginx)。您应该手动创建它,或者让启动脚本检查日志目录并创建它。至于检查conf,只需使用-t来验证配置文件。您添加一个额外的-s命令来发送信号就是告诉nginx在一个命令中做两件不同的事情。如上所示,如果我删除该信号,nginx
命令将不再工作。至于日志,我尝试使用-g
更改目录,但没有成功。我想运行nginx
命令而不运行sudo
。我认为默认的nginx命令需要root权限才能运行——即,如果您的配置使用1024以下的端口(包括端口80、443等)。nginx写入的大多数目录也属于root目录。因此,除非将nginx.conf配置为使用非特权端口和用户可写目录,否则可能会出现错误。FWIW,添加-s stop
允许验证命令在没有sudo
的情况下正确运行。它只是打印警告。在没有该标志的情况下运行会导致命令失败。此外,验证完成后,nginx不应运行。程序应该退出。您可以尝试使用“user”指令在特定用户/组下运行nginx。看见