I get an error when building nginx with docker - docker

I am trying to build springboot, nginx, mysql with docker, other stacks work fine, but nginx returns the following error
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/06/14 03:41:48 [emerg] 1#1: unexpected end of file, expecting "}" in /etc/nginx/conf.d/app.conf:11
nginx: [emerg] unexpected end of file, expecting "}" in /etc/nginx/conf.d/app.conf:11
I think the error is a grammatical error, Below is the content of the nginx/conf.d/app.conf file.
server {
listen 80;
access_log off;
location / {
proxy_pass http://app:8080;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
The error log says there is a problem in the 11th line in app.conf, but I do not know the nginx syntax, so I have no idea what the problem is. Any advice would be appreciated.

Related

Connection refused when trying to use Nginx Docker reverse proxy

I am trying to setup Nginx Docker reverse proxy with a single container and am getting connection refused. See attachment for error.Results of browsing to https://IPAddressofServer
I am getting the following error in the logs:
2021/10/21 17:41:00 [warn] 19199#19199: conflicting server name "" on 0.0.0.0:443, ignored
Can anyone assist with this issue?
OS is Ubuntu 20 running on an Azure VM
Here is my .conf configuration within /etc/nginx/sites-enabled
`server {
listen 443 ssl;
server_name DNSNameofServer;
ssl_certificate /etc/ssl/certs/ChainedCertName.pem;
ssl_certificate_key /etc/ssl/certs/KeyFileName.key-plain.key;
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://DNSNameofServer:8088;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}`

How fix nginx error "invalid number of arguments"?

i try redirect to proxy-server nginx.
location /phpmyadmin {
proxy_http_version 1.1;
proxy_pass https://${PMA}:5000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
But i get error:
nginx: [emerg] invalid number of arguments in "proxy_set_header" directive in /etc/nginx/nginx.conf:26
full code for inspect error in this listing, because i'm real can't find some error's (${env} = correctry changing in script
user root;
worker_processes auto;
pcre_jit on;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
keepalive_timeout 3000;
sendfile on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/nginx.crt;
ssl_certificate_key /etc/ssl/nginx.key;
root /home;
index default.html /default.html;
location /phpmyadmin {
proxy_http_version 1.1;
proxy_pass https://${PMA}:5000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
}
location /wordpress {
return 307 http://${WP}:5050/;
}
location / {
try_files /default.html default.html default.htm;
}
}
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
}
daemon off;
how much simvols need for post)
I used envsubst for environment replacing, and this util tried swap $host and other nginx envs, solved with:
envsubst '\$WP \$PMA' < nginx.template.conf > nginx.ready.conf; rm nginx.template.conf
Expanding on the working answer from #mikhail-prigorodov:
The situation described by the OP arises when using the Nginx Docker container with Docker Compose. In the documentation, it reads:
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But this image has a function, which will extract environment variables before nginx starts.
So, if you are using environment variables in your docker-compose.yml as part of a 12-Factor App design, you have to figure out how to get them into your Nginx config file properly.
The solution in the Nginx Docker documentation is to run envsubst on a template configuration file and send the output to the Nginx config file. The Dockerfile syntax, which is mentioned in this GitHub issue is:
CMD envsubst < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'
But that solution runs into a problem if you have Nginx-defined variables AND environment variable placeholders in your configuration template. In the directory where I'm building my Nginx container (where my Dockerfile is), I have a templates directory with a file called default.conf.template, as directed in the documentation. The file contains Nginx variables and environment variables. For example:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
location /static {
alias /usr/share/nginx/html/${STATIC_DIR};
}
The problem (I think) is that envsubst is looking for the "$" character that marks the start of the environment variables. In any case, you'll find that after running envsubst successfully, each line in your new Nginx config file that has a Nginx-defined variable (leading "$") in the template gives an error when you try and start Nginx.
To solve this problem, use the syntax provided by #mikhail-prigorodov. Applied to my example:
CMD envsubst '\$STATIC_DIR' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'
This was the solution that worked for me after hours of frustration.

Docker- nginx -Reverse proxy : host not found in upstream when building with docker-compose

I am using NGINX container to redirect certain requests to another container.While running docker-compose up -d , i am getting bellow error.
" 2019/09/26 18:05:00 [emerg] 1#1: host not found in upstream "abcplus-visualize:61613" in /etc/nginx/nginx.conf:10
nginx: [emerg] host not found in upstream "abcplus-visualize:61613" in /etc/nginx/nginx.conf:10"
below is my docker-compose.yml file
version: '2'
services:
reverseproxy:
image: reverseproxy
ports:
- 49665:2181
restart: always
abcplus-visualize:
depends_on:
- reverseproxy
image: abcplus-visualize:latest
restart: always
below is my nginx.conf file
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
upstream docker-abcplus {
server abcplus-visualize:61613;
}
server {
listen 2181;
server_name localhost;
location / {
proxy_pass http://docker-abcplus;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
try to use :
upstream docker-abcplus {
server abcplus-visualize:61613 max_fails=6 fail_timeout=30s;
}
I think your upstream fails too fast before the app is running
There was issue with Server name which we are giving in upstream.
I tried with abcplus-visualize instead of abcplus-visualize , its working fine.
May be while starting docker-compose server name with hypen("-") it is not understating.

service nginx restart fails

I checked the config syntax by run nginx -t then get the results:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
But when I run service nginx restart goes fail.
I have a config file named a.com in the sites-enabled folder, here's the content:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name a.com;
# root /usr/share/nginx/html;
# index index.html index.htm;
root /home/a/public;
client_max_body_size 10G;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}
I'm at Ubuntu 14.10 and want to deploy a rails server.
I kill the nginx's process manually, then start nginx again, solved the problem.
I had this issue and using sudo solved it:
sudo service nginx restart
It might help to enable logs to checks the errors:
https://www.nginx.com/resources/admin-guide/logging-and-monitoring/

Rails does not work when terminal exits

I run a rails app.
rails s -p 5000 -e production &
The website works fine.
But, when terminal (which runs above command) exits, the website only shows blank page.
When I open terminal again, the rails process is still running.
I check nginx log. After terminal exits, nginx seems stop talking rails. Nginx just returns HTTP 200.
Below is nginx config.
server {
listen 80;
server_name mydomain.org;
rails_env production;
root /home/user/website/public;
client_max_body_size 10M;
access_log /opt/nginx/logs/website.log;
error_log /opt/nginx/logs/website_err.log;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I think you missing -d or --daemon option for run server as a daemon:
rails s -p 5000 -e production -d &

Resources