在nginx conf中使用变量

时间:2019-04-04 14:13:32

标签: nginx nginx-reverse-proxy nginx-config

这适用于我的Nginx配置:

    # This works
    proxy_pass http://GitLab-CE:9080;

...但这不是:

    # does not work
    set $upstream_gitlab GitLab-CE;
    proxy_pass http://$upstream_gitlab:9080;

这是从另一个使用连字符和不同端口的工作示例中复制的。

    # this works
    set $upstream_deluge binhex-delugevpn;
    proxy_pass http://$upstream_deluge:8112;

我认为可能与破折号有关,但是我还有另一个配置,该配置的名称中也使用了连字符(参见上文),并且可以使用。我尝试了各种形式的报价,但这似乎也无济于事。这可能是怎么回事?我很茫然。 GitLab-CE不能正常工作,而binhex-delugevpn可以正常工作是什么? Nginx看到CE具有一些十六进制数学吗?

完整上下文:

# make sure that your dns has a cname set for gitlab and that your gitlab container is not using a base url

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name gitlab.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth, fill in ldap details in ldap.conf
    #include /config/nginx/ldap.conf;

    location / {
        # enable the next two lines for http auth
        auth_basic "Restricted";
        auth_basic_user_file /config/nginx/.htpasswd;

        # enable the next two lines for ldap auth
        #auth_request /auth;
        #error_page 401 =200 /login;

        include /config/nginx/proxy.conf;
        resolver 127.0.0.11 valid=30s;
        set $upstream_gitlab GitLab-CE;
        proxy_pass http://$upstream_gitlab:9080;
    }
}

我应该注意到127.0.0.11确实是正确的解析器,名称GitLab-CE和binhex-delugevpn可以正确解析。

当然,仅在一次引用变量时就不需要使用变量,但这遵循linuxserver.io的letencrypt Docker映像中的模板。

编辑:更多上下文

这是/config/nginx/nginx.conf。

我未修改它。

## Version 2018/01/29 - Changelog: https://github.com/linuxserver/docker-letsencrypt/commits/master/root/defaults/nginx.conf

user abc;
worker_processes 4;
pid /run/nginx.pid;
include /etc/nginx/modules/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        client_max_body_size 0;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /config/log/nginx/access.log;
        error_log /config/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##
        include /etc/nginx/conf.d/*.conf;
        include /config/nginx/site-confs/*;

}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}
daemon off;

编辑2:

我已经验证了使用变量时Nginx似乎在进行一些“较低级”的转换。

我将GitLab容器重命名为gitlab-ce,并且运行良好。 我将洪水容器重命名(并对.conf进行了适当的编辑),将其重命名为binhex-deLugevpn,并且该容器停止工作。

然后我将其重命名为binhex-deluge,但是在.conf文件中,我放置了set $upstream_deluge bInHeX-dElUgEvPn;

它奏效了。因此,来自linuxserver / letsencrypt的nginx(1.14.2)似乎对变量进行了一些较低的转换。

我尝试看find /config -type f -print0 | xargs -0 grep -i lower却一无所获。

0 个答案:

没有答案