找回密码
 新建账号

nginx 中的相对路径

[复制链接]
php 发表于 2024/9/14 14:09 | 显示全部楼层 |阅读模式
nginx 对相对路径的解析并不统一,也就是说,对不同的配置选项使用相对路径,它们相对的目录并不一样。

对大多数 nginx 配置选项来说,如果使用相对路径,它们相对的是 nginx 的编译前缀指定的目录,即编译 nginx 时使用 ./configure --prefix 指定的 nginx 的安装路径,它是编译完成后安装 nginx 的主目录,加 -V 运行 nginx 可以看到 nginx 的编译参数。
  1. nginx -V
复制代码
可以看到类似于这样的内容
  1. configure arguments: --prefix=/application/wuxiancheng/nginx/1.27.0 --with-file-aio --with-http_addition_module --with-http_realip_module --with-http_gunzip_module --with-http_ssl_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-threads
复制代码
这个路径前缀也可以在运行 nginx 时使用 -p 参数设置
  1. nginx -p /application/wuxiancheng/foo/bar
复制代码
少数配置选选项相对于 nginx 主配置文件所在的目录,nginx 主配置文件通常是 <prefix>/conf/nginx.conf,其中 <prefix> 是路径前缀,可以在运行 nginx 时使用 -c 参数设置,文件名可以和 nginx 完全没有关系,也可以没有扩展名 .conf
  1. nginx -c /foo/bar/baz.conf
复制代码
这些配置选项包括但不限于
  1. include
  2. ssl_certificate
  3. ssl_certificate_key
复制代码
使用绝对路径可以避免出现预料以外的路径解析。
使用命令行参数 -p -c 设置的值优先级高于编译 nginx 时所设定的值。
以上示例运行 nginx 时只写了一个参数,实际运行时需要结合需要把所有要加的参数都写上去。

手机版|轻松E站

GMT+8, 2024/9/19 09:48

快速回复 返回顶部 返回列表