I've set up my site based on the instructions here.
However, when I go to the URL specified in my nginx sites-available settings, I just get the default nginx page ("welcome to nginx!"). I've tried looking at this question, but even deleting /etc/nginx/sites-enabled/default doesn't seem to do anything.
My /etc/nginx/sites-available/eng_blog file:
server {
listen 80;
server_name eng.camdar.io;
location = /favicon.io {access_log off; log_not_found off;}
location /static/ {
root /root/eng_blog;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/root/eng_blog/eng_blog.sock
}
}
My /etc/uwsgi/sites/eng_blog.ini
[uwsgi]
project = eng_blog
base = /root
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
wsgi-file = eng_blog/wsgi.py
master = True
processes = 5
socket = %(base)/%(project)/%(project).sock
chmod-socket = 666
uid = www-data
gid = www-data
vacuum = true
/etc/init/uwsgi.conf
description "uWSGI application server in Emperor mode"
start on runlevel [2345]
stop on runlevel [!2345]
setuid root
setgid www-data
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
The tutorial claims that, after symlinking /etc/nginx/sites-enabled/eng_blog to /etc/nginx/sites-available/eng_blog, things should just "work", but I'm still seeing the default Nginx screen. Help?
EDIT:
I fixed the above issue by including sites-enabled in nginx.conf. However, now uwsgi seems to get permission denied errors, which is strange because I'm pretty sure I set all of the permissions right.
Related
I tried to follow the nginx document here https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html. But stuck at Configure nginx for your site. I restarted nginx and it said "nginx: [emerg] open() "/home/hanys/oligoweb/uwsgi_params" failed (13: Permission denied) in /etc/nginx/sites-enabled/oligoweb.conf:19".
My site.ini:
[uwsgi]
chdir = /home/hanys/oligoweb/
module = oligoweb.wsgi
home = /home/hanys/.virtualenv/oligo-env
master = true
processes = 10
socket = /home/hanys/oligoweb/oligoweb.sock
chmod-socket = 666
vacuum = true
daemonize = /home/hanys/uwsgi-emperor.log
uid = www-data
gid = www-data
my site.conf in /etc/nginx/sites-available/
upstream django {
server unix:///home/hanys/oligoweb/oligoweb.sock;
}
server {
listen 80;
server_name IP address here;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /static {
alias /home/hanys/oligoweb/static;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/hanys/oligoweb/uwsgi_params;
}
}
uwsgi_params has 664 permission. I tried chmod 777 uwsgi_params but it didnt work.
Any help will be appreciated!
In general, uwsgi_params is already shipped with your Nginx, so all you need is include uwsgi_params (so it refers to /etc/nginx/uwsgi_params or similar).
If that is not the case, you will likely also need to give Nginx enough permissions to read the directory structure that file is in, not just the file itself.
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
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;
}
}
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
-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.