通过-c标志向nginx传递相对文件名
nginx通过命令行接受参数以指定配置文件的位置:通过-c标志向nginx传递相对文件名,nginx,Nginx,nginx通过命令行接受参数以指定配置文件的位置: -c filename : set configuration file 对于我的用例,filename必须是相对于当前工作目录的路径,但nginx似乎总是相对于其安装位置来解释filename: $ nginx -c nginx.conf => nginx: [emerg] open() "/usr/local/Cellar/nginx/1.4.1/nginx.conf" failed (2: No such file or d
-c filename : set configuration file
对于我的用例,filename
必须是相对于当前工作目录的路径,但nginx似乎总是相对于其安装位置来解释filename
:
$ nginx -c nginx.conf
=> nginx: [emerg] open() "/usr/local/Cellar/nginx/1.4.1/nginx.conf" failed (2: No such file or directory)
甚至可以向nginx传递文件名的cwd相对路径吗?“否”是一个可接受的答案。它与配置和编译期间传递给configure
的--前缀相关,在大多数情况下可能是/usr
,因此它与此相关
例如,在我的机器上:
$nginx-V
产生:
nginx version: nginx/1.2.6
built by gcc 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
TLS SNI support enabled
configure arguments: --prefix=/usr --with-http_ssl_module ... other stuff...
请注意,--prefix=/usr
,因此这是与-c
相关的基本路径
因此:
$nginx-t-cnginx.conf
在以下情况下失败:
$ nginx -t -c nginx.conf
nginx: [emerg] open() "/usr/nginx.conf" failed (2: No such file or directory)
很明显,nginx是相对于--prefix
的值看的,您试过“/nginx.conf”吗?而且,这对于安全来说可能是绝对不可能的reasons@Wug:这也是我所怀疑的。(nginx-c./nginx.conf
给出了相同的错误)您可以使用nginx-c$PWD/nginx.conf
谢谢。那么说nginx不能接受相对于当前工作目录的路径名是真的吗?@pje是的,似乎是这样。