I am experiencing the following error with my multi-container Docker setup after running docker-compose build && docker-compose up and attempting to hit my index page:
[crit] 8#8: *1 connect() to unix:/tmp/uwsgi.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/uwsgi.sock:", host: "192.168.99.100"
Here is my docker-compose.yml:
web:
restart: always
build: ./web-app
expose:
- "8000"
command: /usr/local/bin/uwsgi --ini sample-uwsgi.ini
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
links:
- web:web
nginx/Dockerfile
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD sample-nginx.conf /etc/nginx/conf.d/
nginx/sample-nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
}
web-app/Dockerfile
FROM ansible/ubuntu14.04-ansible:stable
WORKDIR /root
ADD application.py application.py
ADD requirements.txt requirements.txt
ADD sample-uwsgi.ini sample-uwsgi.ini
ADD ansible /srv/ansible
WORKDIR /srv/ansible
RUN ansible-playbook container-bootstrap.yml -c local
web-app/sample-uswgi.ini
[uwsgi]
module = application
callable = app
master = true
processes = 5
socket = /tmp/uwsgi.sock
chown-socket = www-data:www-data
vacuum = true
enable-threads=True
die-on-term = true
UPDATE
On advice from #kryten I will be using TCP/IP
Updated nginx.conf:
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
uwsgi_pass localhost:8000;
include uwsgi_params;
}
}
Updated uwsgi.ini:
[uwsgi]
module = application
callable = app
master = true
processes = 5
socket = localhost:8000
chown-socket = www-data:www-data
vacuum = true
enable-threads=True
die-on-term = true
and am now pursuing the following error:
[error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "192.168.99.100"
Since web and nginx are separate containers, nginx needs to connect to another computer over TCP. Linking the containers does most of the work already, you just have to point the upstream to web:8000 instead of localhost.
It looks like one of your applications is attempting to connect via a Unix socket instead of over TCP/IP.
This will not work from different containers, because the filesystem in one container (where the socket lives) is not accessible in the other container.
The solution is to reconfigure your application to connect over TCP/IP instead of a Unix socket.
It might be possible to connect by exposing the location in the filesystem where the socket resides to the other container, but I've never tried this & don't know if it would work.
Related
I want to redirect the requests to the /api to the node app running on localhost:3000 using NGINX
I'm trying to redirect the requests using proxy_pass
server {
listen 80;
server_name localhost;
root /var/www/mydomain/html;
index index.html index.htm;
location /api {
proxy_pass http://127.0.0.1:3000/;
}
}
If I access localhost in my browser I see the frontend application, so that's correct.
If I hit http://127.0.0.1:3000 (or localhost:3000) I get a response from the node API, so that's correct.
But when I try to access localhost/api I get the following error:
[error] 6#6: *3 connect() failed (111: Connection refused) while connecting >to upstream, client: 172.18.0.1, server: localhost, request: "GET /api >HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "localhost"
EDIT:
I'm using a docker-compose to manage the services:
services:
nginx:
container_name: nginx-local
build:
context: .
dockerfile: ./nginx.dev.dockerfile
volumes:
...
ports:
- '80:80'
networks:
- local-network
node:
container_name: node-api
build:
context: ./api
dockerfile: .docker/node.dockerfile
ports:
- '3000:3000'
networks:
- local-network
Based on the docker-compose file the nginx config for needs to be changed to
server {
listen 80;
server_name localhost;
root /var/www/mydomain/html;
index index.html index.htm;
location /api {
proxy_pass http://node-api:3000/;
}
}
This is due to the separate docker image for the node application. So you need to use the proxy pass to point to the correct location.
We had installed wildfly for a couple of time working correctly. We configured right now Nginx as reverse proxy for wildfly.
We're getting on OPTIONS method 405 Method Not Allowed. Here is the configuration of nginx.
/etc/nginx/conf.d/wildfly.conf
upstream wildfly {
server 127.0.0.1:8081;
}
server {
listen 8080;
server_name guest1;
location/ {
proxy_pass http://wildfly;
}
}
Error obtained after installing nginx:
This is the error got by nginx:
2017/06/23 08:16:54 [crit] 1386#0: *9 connect() to 127.0.0.1:8081 failed (13: Permission denied) while connecting to upstream, client: 172.28.128.1, server: guest1, request: "OPTIONS /commty/cmng/users HTTP/1.1", upstream: "http://127.0.0.1:8081/commty/cmng/users", host: "guest1:8080"
What I'm missing?
I've done the following to finally make it work on CentOS7 + Wildfly.
Vagrant up
Install NGINX
yum install epel-release
yum install nginx
Configure /etc/nginx/nginx.conf (default configuration)
Configure /etc/nginx/conf.d/wildfly.conf (using port 80 for nginx and 8080 for wildfly)
upstream wildfly {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name guest1;
location / {
proxy_pass http://wildfly;
}
}
Also set SELinux permissive for let nginx work.
$ setenforce permissive
After that wildfly is working properly through nginx.
I'm serving my app with uWSGI using uwsgi --http-socket 127.0.0.1:3031 -w app:app, which works when I go to 127.0.0.1:3031 in a browser. I want to use Nginx, so I told it to uwsgi_pass to that url, but now I get a 502 Bad Gateway error. How do I put uWSGI behind Nginx?
server {
listen 8080;
server_name 127.0.0.1;
location / {
uwsgi_pass 127.0.0.1:3031;
include uwsgi_params;
}
location /static {
alias /static/folder/location;
}
}
2016/05/16 19:50:09 [error] 6810#0: *4 upstream prematurely closed
connection while reading response header from upstream, client:
127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream:
"uwsgi://127.0.0.1:3031", host: "127.0.0.1:8080"
You can use http-socket between nginx and uWSGI.
For example, if you launch your python app with uWSGI:
uwsgi --http-socket 127.0.0.1:3031 --wsgi-file application.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
Configure Nginx with:
location / {
proxy_pass http://127.0.0.1:3031/;
}
Use socket, not http-socket.
uwsgi --socket 127.0.0.1:3031 -w app:app
http-socket makes uWSGI act like a web server that speaks HTTP, and is not correct if you're using Nginx, since it understands uWSGI directly.
I'm experiencing 502 gateway errors when accessing my IP on nginx(http://52.xx.xx.xx/), the logs simply says this:
2015/09/18 13:03:37 [error] 32636#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx.xx, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "xx.xx.xx.xx"
my nginx.conf file
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name xx.xx.xx.xx; # substitute your machine's IP address or FQDN
charset utf-8;
access_log /home/ubuntu/test_django/nginx_access.log;
error_log /home/ubuntu/test_django/nginx_error.log;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/test_django/static/media/; # your Django project's media files - amend as required
}
location /static {
alias /home/ubuntu/test_django/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/ubuntu/test_django/uwsgi_params; # the uwsgi_params file you installed
}
}
Is there anything wrong with nginx.conf file.....if i use default conf then it is working.
I resolved it by changing the socket configuration in uwsgi.ini
from socket = 127.0.0.1:3031, to socket = :3031. I was facing this issue when I ran nginx in one Docker container and uWSGI in another. If you are using command line to start uWSGI then do uwsgi --socket :3031.
Hope this helps someone stuck with the same issue, during deployment of a Django application using Docker.
change this address:
include /home/ubuntu/test_django/uwsgi_params;
to
include /etc/nginx/uwsgi_params;
I ran into this issue when setting up the env by nginx + gunicorn and solve it by
adding '*' to ALLOWED_HOSTS or your specific domain.
In my case with a debian server it worked moving:
include /etc/nginx/uwsgi_params;
In the location tag in my nginx server config file, like this:
location /sistema {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix://path/sistema.sock;
}
Also, check you have the following packages installed:
uwsgi-plugin-python
pip3 install uWSGI did the trick for me :D
I am experiencing the following error with my multi-container Docker setup after running docker-compose build && docker-compose up and attempting to hit my index page:
[error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.99.1, server: localhostz, request: "GET / HTTP/1.1", upstream: "uwsgi://172.17.0.39:8000", host: "192.168.99.100"
Here is my docker-compose.yml:
web:
restart: always
build: ./web-app
expose:
- "8000"
command: /usr/local/bin/uwsgi --ini sample-uwsgi.ini
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
links:
- web:web
nginx/Dockerfile
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD sample-nginx.conf /etc/nginx/conf.d/
nginx/sample-nginx.conf
upstream flask {
server web:8000;
}
server {
listen 80;
server_name localhostz;
charset utf-8;
client_max_body_size 75M;
location / {
uwsgi_pass flask;
include uwsgi_params;
}
}
web-app/Dockerfile
FROM ansible/ubuntu14.04-ansible:stable
WORKDIR /root
ADD application.py application.py
ADD requirements.txt requirements.txt
ADD sample-uwsgi.ini sample-uwsgi.ini
ADD ansible /srv/ansible
WORKDIR /srv/ansible
RUN ansible-playbook container-bootstrap.yml -c local
web-app/sample-uswgi.ini
[uwsgi]
module = application
callable = app
master = true
processes = 5
socket = web:8000
chown-socket = www-data:www-data
vacuum = true
enable-threads=True
die-on-term = true
Please do not post suggestions regarding a single container setup. I am doing as an exercise in being able to scale Docker app containers served under a single nginx container.
Secret sauce was changing the socket line in sample-uwsgi.ini to:
socket = 0.0.0.0:8000