Nginx - 4021#0 - Problems setting up - django

-I'm using a virtual machine with Ubuntu 12.04.3 LTS
-I'm doing a Django project with Uwsgi + nginx
-I added "192.168.33.50 myproject.com" to my hosts file
-I started uwsgi + supervisor + nginx process
-When I'm trying to access to myproject.com, I'm getting this error in /var/log/nginx/error.log:
2013/11/13 07:43:21 [crit] 14741#0: *1 connect() to
unix:/tmp/uwsgi_myproject.sock failed (2: No such file or
directory) while connecting to upstream, client: 192.168.33.1, s$
Edition 1
This is my uwsgi.ini:
[uwsgi]
module = myproject.wsgi:application
master workers = 3
logto = /vagrant/log/uwsgi.log
socket = /tmp/uwsgi_myproject.sock
pidfile = /tmp/uwsgi_myproject.pid chmod-socket = 666
auto-procname need-app vacuum
Edition 2
If I execute this command in console:
uwsgi --ini /vagrant/uwsgi.ini --chdir /vagrant/myproject/ --socket
/tmp/uwsgi_myproject.sock --pidfile /tmp/myproject.pid
With that command, uwsgi starts and I can access to myproject.com but it's supossed that uwsgi starts with supervisor of django
Edition 3
This is myproject.conf in /etc/nginx/conf.d/
server {
listen 80;
charset utf-8;
sendfile off;
# ONIX files
client_max_body_size 100M;
location /media/imagen {
include uwsgi_params;
#The uwsgi_pass must comply with the details in supervisord.conf
uwsgi_pass unix:/tmp/uwsgi_myproject.sock;
}
location /media/resources/protected {
root /vagrant/myproject/myproject;
internal;
}
location /media {
root /vagrant/myproject/myproject;
}
location /static {
root /vagrant/myproject/myproject;
}
location / {
include uwsgi_params;
#The uwsgi_pass must comply with the details in supervisord.conf
uwsgi_pass unix:/tmp/uwsgi_myproject.sock;
uwsgi_read_timeout 300;
}
}
EDITED: ADDED SUPERVISOR.CONF ASKED BY #ChrisC
[supervisord]
logfile={{ PROJECT_DIR }}/../log/supervisord.log
pidfile=/tmp/supervisor_PROJECTNAME.pid
user=PROJECTNAME
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8,LC_LANG=en_US.UTF-8
[unix_http_server]
file = /tmp/supervisor_PROJECTNAME.sock
[program:__defaults__]
directory={{ PROJECT_DIR }}
startsecs=5
[program:autoreload]
exclude=true
[program:uwsgi]
command=uwsgi --ini {{ PROJECT_DIR }}/../uwsgi.ini --chdir {{ PROJECT_DIR }} --socket /tmp/uwsgi_PROJECTNAME.sock --pidfile /tmp/uwsgi_PROJECTNAME.pid
stopsignal=INT

The problem was in the configuration of the supervisor. The supervisor wasn't loading the uwsgi process well.

Related

Error on deploying django + uwsgi + nginx

I'm trying to deploy a django project with uWSGI and nginx. I have the next configuration files:
uwsgi.ini
[uwsgi]
#Django-related settings
chdir = /home/amlalchy/api_aml_platform
module = api.wsgi
#static-map = /static=/home/amlalchy/api_aml_platform/services/static
#Process-related settings
master = true
processes = 10 
# The socket(use the full path to be safe)
socket = /tmp/aml.sock
chmod-socket = 664
uid = www-data
gid = www-data 
# Clear environment on exit
vacuum = true
uwsgi.service
[Unit]
Description=uWSGI Emperor service
After=network.target
[Service]
#User=amlalchy
#Group=www-data
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown amlalchy:www-data /run/uwsgi'
ExecStart=/bin/bash -c 'cd /home/amlalchy/api_aml_platform && source /home/amlalchy/anaconda3/bin/activate AmlPlatform && uwsgi --ini /etc/uwsgi/sites/uwsgi.ini'
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
api.conf for the nginx configuration
server {
listen 80;
server_name server.prueba.com;
charset utf-8;
client_max_body_size 128M;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
root /home/amlalchy/api_aml_platform/services;
}
location /media {
root /home/amlalchy/api_aml_platform;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/aml.sock;
uwsgi_read_timeout 300s;
uwsgi_send_timeout 300s;
}
}
I'm getting this error in /var/log/enginx/error.log :
2020/01/13 10:30:12 [error] 12641#12641: *1 open() "/home/amlalchy/api_aml_platform/services/static/css/global.css" failed (2: No such file or directory), client: 127.0.0.1, server: server.prueba.com, request: "GET /static/css/global.css HTTP/1.1", host: "127.0.0.1", referrer: "http://127.0.0.1/api/login/
I am newbie and I don't know what I'm missing because the static files exists... so I would be really grateful for any tip on my error.
Thanks in advance.
Where are your static files (css/js/images)? How do you deploy them?
As #ruddra suggested, how do you run your?
./manage.py collectstatic

How can I configure nginx with multiple uwsgi vassals (with websockets) in emperor mode?

I'm having issues running 2 vassals in emperor mode (for a main app + websocket) behind an nginx server. Everything seems to be running well, but all the websocket requests return error 502 bad gateway. The websocket app is running django-websocket-redis. Any ideas where I went wrong?
Running from upstart
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals/ --logto /var/log/uwsgi.log
With /etc/uwsgi/vassals/dashdb_websocket.ini:
# dashdb_websocket.ini file
[uwsgi]
umask = 002
home = /opt/dashdb/venv/dashdb-3.5
plugin = python35
chdir = /opt/dashdb
master = true
no-orphans = true
die-on-term = true
memory-report = true
env = DJANGO_SETTINGS_MODULE=dashdb.settings.opener
socket = /var/run/uwsgi/dashdb_ws.sock
pythonpath = /opt/dashdb
module = dashdb.wsgi_websocket
threads = 1
processes = 1
http-websockets = true
gevent = 1000
# Log file location
daemonize = /var/log/uwsgi/dashdb_websocket.log
With /etc/uwsgi/vassals/dashdb.ini:
# dashdb.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /opt/%n
# Django's wsgi file
module = dashdb.wsgi
# the virtualenv (full path)
home = /opt/dashdb/venv/%n-3.5
plugin = python35
# settings location
env = DJANGO_SETTINGS_MODULE=dashdb.settings.opener
# Process-related settings
# master
master = true
# maximum number of worker processes
processes = 3
# the socket (use the full path to be safe)
socket = /var/run/uwsgi/%n.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
# Log file location
daemonize = /var/log/uwsgi/%n.log
and nginx config:
upstream django_dashdb {
server unix:/var/run/uwsgi/dashdb.sock;
}
server {
listen *:80;
server_name MY_DOMAIN;
server_tokens off;
root /opt/dashdb;
charset utf-8;
# Increase this if you want to upload large attachments
# Or if you want to accept large git objects over http
client_max_body_size 250m;
# Individual nginx logs for this GitLab vhost
access_log /var/log/dashdb/dashdb_access.log;
error_log /var/log/dashdb/dashdb_error.log;
# Django media
location /media {
alias /opt/dashdb/media;
}
# Django static
location /static {
alias /opt/dashdb/static;
}
location / {
uwsgi_read_timeout 180;
uwsgi_pass django_dashdb;
include /opt/dashdb/uwsgi_params;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://unix:/var/run/uwsgi/dashdb_ws.sock;
}
error_page 502 /502.html;
}
Errors in the logs:
2017/03/20 23:27:51 [error] 3586#3586: *2759 upstream prematurely closed connection while reading response header from upstream, client:
10.31.32.22, server: MY_DOMAIN...com, request: "GET /ws/builds?subscribe-broadcast&echo HTTP/1.1", upstream: "http://unix:/var/run/uwsgi/dashdb_ws.sock:/ws/builds?subscribe-broadcast&echo", host: "MY_DOMAIN...com"
I needed to set
http-socket = /var/run/uwsgi/dashdb_ws.sock
instead of
socket = /var/run/uwsgi/dashdb_ws.sock
in the websocket uwsgi config ini

Linode Django uwsgi Nginx

The following setup is only letting me see the default Nginx html page. How can I get to Django?
I've been following Linode's documentation on how to set this up (and numerous other tutorials), but they don't use systemd, so things are a bit different.
https://www.linode.com/docs/websites/nginx/deploy-django-applications-using-uwsgi-and-nginx-on-ubuntu-14-04
I am using Linode with Fedora24. I have installed my virutalenv at
/home/ofey/djangoenv and activated it,
Django is installed using pip at
/home/ofey/qqiProject
Into the virtualenv I've installed uwsgi.
Firstly,
/etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
After=syslog.target
[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
This executes,
/etc/uwsgi/sites/qqiProject.ini
[uwsgi]
project = qqiProject
base = /home/ofey
chdir = %(base)/%(project)
home = %(base)/djangoenv
module = %(project).wsgi:application
master = true
processes = 2
socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacuum = true
Also,
/etc/nginx/sites-available/qqiProject
server {
listen 80;
server_name qqiresources.com www.qqiresources.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/django/qqiProject;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/django/qqiProject/qqiProject.sock;
}
}
The file /etc/nginx/nginx.conf has not been changed.
The user is ofey, I've used,
$ sudo systemctl daemon-reload
$ sudo systemctl restart nginx
$ sudo systemctl start uwsgi.service
Started Django with,
$ python manage.py runserver
To Django's settings.py I turned off debugging and added a host
DEBUG = False
ALLOWED_HOSTS = ['qqiresources.com']
I have also created a symbolic link,
sudo ln -s /etc/nginx/sites-available/qqiProject /etc/nginx/sites-enabled
Any help would be greatly appreciated,
Thanks
The following is working for me, however I am not sure if this is the correct or most efficient way to do it, especially where the sockets are concerned.
systemd runs the uwsgi.service and can be started with,
$ sudo systemctl start uwsgi.service
Sometimes it is necessary to reload systemd using,
$ sudo systemctl daemon-reload
/etc/sysemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
After=syslog.target
[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
This calls the binary inside my django virtual environment directory with,
ExecStart=/home/ofey/djangoenv/bin/uwsgi
and also takes us to /etc/uwsgi/sites where the uwsgi configuration files is called djangoForum.ini
/etc/uwsgi/sites/djangoForum.ini
[uwsgi]
project = djangoForum
base = /home/ofey
chdir = %(base)/%(project)
home = %(base)/djangoenv
module = crudProject.wsgi:application
master = true
processes = 2
socket = 127.0.0.1:3031
chmod-socket = 664
vacuum = true
Django is at /home/ofey/djangoForum and my django project is at /home/ofey/djangoForum/crudProject
/etc/nginx/nginx.conf
events {
worker_connections 1024;
}
http{
upstream django {
# connect to this socket
# server unix:///tmp/uwsgi.sock; # for a file socket
server 127.0.0.1:3031; # for a web port socket
}
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name example.com; # substitute your machine's IP address or FQDN
charset utf-8;
#Max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ofey/djangoForum/fileuploader/uploaded_files; # your Django project's media files
}
location /static {
alias /home/ofey/djangoForum/noAppBoundStaticDirectory; # your Django project's static files
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
# uwsgi_pass 127.0.0.1:3031;
include /etc/nginx/uwsgi_params; # or the uwsgi_params you installed manually
}
}
}
nginx can be turned on with,
$ sudo systemctl start nginx.service
'start' can be replaced with, 'restart' or 'stop'.
These configuration files for uwsgi and nginx worked for me.
Useful links:
https://gist.github.com/evildmp/3094281
https://www.linode.com/docs/websites/nginx/deploy-django-applications-using-uwsgi-and-nginx-on-ubuntu-14-04

502 error ubuntu 14.04, Nginx, uWSGI, python3, and django

I'm trying to get a site up on a digital ocean droplet, running ubuntu 14.04. For some reason though I keep getting 502 errors. It will work seemingly fine for a little bit, and then out of no where I get a 502 error. If I restart uwsgi it seems to solve it, but only temporarily.
Here's my /etc/init/uwsgi.conf
description "uWSGI application server in Emperor mode"
start on runlevel [2345]
stop on runlevel [!2345]
setuid adam
setgid www-data
exec /home/adam/Env/itinerary/bin/uwsgi --emperor /etc/uwsgi/sites
Here's my /etc/uwsgi/sites/itinerary.ini file
[uwsgi]
project = itinerary
base = /home/adam
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacumm = true
Here's my /etc/nginx/sites-available/itinerary file
server {
listen 80;
server_name _;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/adam/itinerary;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/adam/itinerary/itinerary.sock;
}
}

Django uWSGI Nginx

I am following this tutorial but i am having a problem I'm getting a 502 Nginx error.
tutorial link
Ive check the error logs and it says
uwsgi.log
ImportError: No module named khcards.wsgi
my uwsgi file looks like this
[uwsgi]
# variables
projectdomain = khcardsonline.co.uk www.khcardsonline.co.uk
uid = www-data
god = www-data
chmod = 775
# config
plugins = python
master = true
pidfile=/tmp/project-master.pid
chdir = /var/www/example.com/src/khcards
protocol = uwsgi
env = DJANGO_SETTINGS_MODULE=khcards.settings
home = /var/www/example.com/env
pythonpath = /var/www/example.com/src/khcards
module = khcards.wsgi:application
socket = 127.0.0.1:8889
logto = /var/www/example.com/logs/uwsgi.log
#below line runs it as a daemon in background
daemonize = /var/log/uwsgi/khcards.log
my nginx.conf
server {
listen 80;
server_name domain www.domain.co.uk;
root /var/www/example.com/src/khcards;
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/error.log;
location /static/ { # STATIC_URL
alias /var/www/example.com/src/static/static/; # STATIC_ROOT
expires 30d;
}
location /media/ { # MEDIA_URL
alias /var/www/example.com/src/media/; # MEDIA_ROOT
expires 30d;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8889;
}
}
When i run
sudo service uwsgi restart
the terminal spits out
Restarting app server(s) uwsgi [ OK ]
but when i do
sudo service nginx restart
the terminal spits out
Restarting nginx: nginx.
Does this mean Nginx isn't configured correctly?
Try changing
chdir = /var/www/example.com/src/khcards
to
chdir = /var/www/example.com/src