Invalid number of arguments in "upstream" directive
See original GitHub issueHello,
when I’m starting the nginx-proxy, see docker-compose.yml below, I always get the error “dockergen.1 | 2020/09/08 07:50:03 Error running notify command: nginx -s reload, exit status 1”.
After connecting to the docker container and using the configtest I’ll get
service nginx configtest
2020/09/08 07:53:10 [emerg] 103#103: invalid number of arguments in "upstream" directive in /etc/nginx/conf.d/default.conf:67
nginx: [emerg] invalid number of arguments in "upstream" directive in /etc/nginx/conf.d/default.conf:67
nginx: configuration file /etc/nginx/nginx.conf test failed
The generated default.conf is:
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
default $http_x_forwarded_port;
'' $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
default off;
https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers off;
resolver 127.0.0.11;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 80;
access_log /var/log/nginx/access.log vhost;
return 503;
}
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 443 ssl http2;
access_log /var/log/nginx/access.log vhost;
return 503;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
}
#
upstream {
# Cannot connect to network of this container
server 127.0.0.1 down;
}
server {
server_name ;
listen 80 default_server;
access_log /var/log/nginx/access.log vhost;
include /etc/nginx/vhost.d/;
location / {
proxy_pass http://;
}
}
server {
server_name ;
listen 443 ssl http2 default_server;
access_log /var/log/nginx/access.log vhost;
return 500;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
}
I checked the file template at https://github.com/nginx-proxy/nginx-proxy/blob/master/nginx.tmpl. The $host seems empty and so is the $upstream_name. If I delete this entry, everything works as intended, but after registering a new container, the config will be regenerated with the discussed error.
This error happens if a start the nginx-proxy, even without any other container in the same network that should be discovered and without the lets encrypt companion.
If I try this local on my windows machine, everything works. I’ll get the error if I’m on my linux server. I even tried to start the nginx-proxy without the docker-compose file with the command in the documentation, but I’ll get the same error. Is there anything I’m doing wrong?
docker-compose.yml
services:
nginx-proxy:
container_name: nginx-proxy
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
restart: always
image: jwilder/nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- dhparam:/etc/nginx/dhparam
- certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
- nginx-proxy-network
nginx-proxy-letsencrypt:
container_name: nginx-proxy-letsencrypt
depends_on:
- nginx-proxy
restart: always
image: jrcs/letsencrypt-nginx-proxy-companion
volumes:
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- dhparam:/etc/nginx/dhparam:ro
- certs:/etc/nginx/certs
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- "DEFAULT_EMAIL=test@test.com"
networks:
- nginx-proxy-network
networks:
nginx-proxy-network:
external: false
name: nginx-proxy-network
volumes:
conf:
vhost:
html:
dhparam:
certs:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
What I meant was that the nginx.conf file is generated from all docker containers on the host - not just the ones connected to a specific network.
It could be that one of the containers could have an empty (not unset) environment variable named VIRTUAL_HOST or DEFAULT_HOST. This would cause the nginx.conf file to be generated the way you posted it.
@pedro2555 and @tkw1536 thank you so much for your replies!
@tkw1536 you were right! I had also a matomo running with an empty environment variable virtual_host. Thank you for the hint!