nginx 忽略我的包含指令?

tft*_*ftd 4 configuration nginx virtualhost ignore

我目前正在从 Apache 迁移到 nginx。我有几个域将托管在具有一个 IP 地址的同一台机器上。虽然我已经配置了nginx --prefix=/my/path它似乎nginx不包括我的 vhost 配置文件。

我当前的 nginx.conf 看起来像这样:

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    # Don't show server version.
    server_tokens off;

    index index.html index.htm index.php;

    # Default server
    server {
        listen          81 default;
        server_name     _;
        access_log      logs/access.log main;
        server_name_in_redirect  off;
        root  html;
    }

    ## Load virtual host conf files. ##
    include conf/vhosts/*/*.conf; # config/vhosts/domain.com/domain.conf ; subodmain.conf and etc

}
Run Code Online (Sandbox Code Playgroud)

这是我在 config/vhosts/domain.com/domain.com.conf 中唯一的 vhost 配置:

server {
    listen          81;
    server_name     domain.com;
    access_log      logs/domain.com.access.log main;

    root            "/www/domain.com/htdocs";
    index           index.html;
}
Run Code Online (Sandbox Code Playgroud)

我也尝试设置配置文件的绝对路径,但它也不起作用。所有的请求都登陆默认服务器。但是,如果您将 的内容conf/vhosts/domain.com/domain.com.conf插入conf/nginx.conf http{}域中,则效果很好。

几个小时以来,我一直试图弄清楚这一点,但我想我做错了什么?

Mar*_*ald 5

正如文档所述。

从 0.6.7 版本开始,路径是相对于 nginx 配置文件 nginx.conf 的目录,而不是相对于 nginx 前缀目录。

如果您确认该路径是相对于 nginx 配置文件的,那么它仍然不起作用吗?


van*_*ome 5

到目前为止,上面的答案是错误的。根据文档:

nginx 只使用绝对路径,配置文件中的所有相对路径都是相对于 --prefix==PATH 的。

http://wiki.nginx.org/CoreModule