在nginx conf中使用变量

在nginx conf中使用变量,nginx,nginx-reverse-proxy,nginx-config,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_delug

这在我的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的letsencrypt 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在使用变量时似乎正在进行一些“tolower”转换

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

然后我把它重新命名为binhex-pluge,但在.conf文件中我把
设置为$upstream\u-pluge-binhex-plugevpn

它成功了。因此,linuxserver/letsencrypt的nginx(1.14.2)似乎在对变量进行一些较低的转换


我试图查找
find/config-type f-print0 | xargs-0 grep-I lower
,但什么也没找到。

我无法通过引入变量来重现不同的行为。我设置了两个相同的服务器块,除了proxy_pass中的变量之外,它们都能够正确地为我代理。将其添加为答案而不是后期编辑将非常好。