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
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.
I'm trying to deploy my django app on a centOS7 server using VPS with nginx and uwsgi, following this tutorial https://www.youtube.com/watch?v=c_17jALtLbQ&feature=youtu.be. The server is up and running i.e., the homepage (welcome to nginx) is working but when I navigate to a different page it tells me "page not found".
Previously, I also tried using Apache following this https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7. But it tells me "you don't have permission to access /url/".
Following is the code for /etc/nginx/sites-available/sitename:
server{
listen 80;
server_name localhost;
location / {
uwsgi_pass unix:///tmp/main.sock;
include uwsgi_params;
}
location /static/ {
alias /var/www/supplychain/Supply_Chain_Proj/static/;
}
}
And this is my /etc/uwsgi/apps-available/sitename.ini file:
[uwsgi]
vhost = true
plugins = python
socket = /tmp/main.sock
master = true
enable-threads = true
processes = 4
wsgi-file = /var/www/supplychain/Supply_Chain_Proj/supply_chain/wsgi.py
virtualenv = /var/www/venv/site
chdir = /var/www/supplychain/Supply_Chain_Proj
touch-reload = /var/www/supplychain/Supply_Chain_Proj/reload
env = DJANGO_ENV=production
env = ALLOWED_HOSTS=*
I have 3 python django application on same server. And I want to run each service using different port.
ex)
80 for end user
8001 for service provider
8002 for service operator
But I have no idea how can I do this.
Now, one uwsgi service is running using systemctl.
This is my uwsgi.service.
# uwsgi.service
[Unit]
Description=uWSGI
After=syslog.target
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /var/run/uwsgi; chown root:ubuntu
/var/run/uwsgi; chmod g+w /var/run/uwsgi;'
ExecStart=/bin/bash -c 'source /var/www/html/remosys/bin/activate; uwsgi --ini /var/www/html/remosys/uwsgi.ini'
#Restart=always
Restart=on-failure
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
And uwsgi.ini is the following.
[uwsgi]
uid = ubuntu
gid = ubuntu
# Django-related settings
# the base directory (full path)
chdir = /var/www/html/remosys/remoshin
# Django's wsgi file
module = remoshin.wsgi
# the virtualenv (full path)
home = /var/www/html/remosys
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2
threads = 1
# the socket (use the full path to be safe
socket = /var/run/uwsgi/master.sock
pidfile = /var/run/uwsgi/master.pid
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
thunder-lock = true
max-requests = 6000
max-requests-delta = 300
# log
logto = /var/log/uwsgi/uwsgi.log
deamonize = /var/log/uwsgi/uwsgi-#(exec://date +%Y-%m-%d).log
log-reopen = true
And my nginx setting is the following.
# the upstream component nginx needs to connect to
upstream django {
# for a file socket
server unix:///var/run/uwsgi/master.sock;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
# substitute your machine's IP address or FQDN
server_name localhost
charset utf-8;
location /clinic {
# your Django project's static files - amend as required
alias /home/ubuntu/public_html/clinic;
}
# max upload size
# Django media
location /static {
# your Django project's static files - amend as required
alias /home/ubuntu/remosys/remoshin/apiv1/static;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
# the uwsgi_params file you installed
include /var/www/html/remosys/uwsgi_params;
}
}
I want to know how can I make settings in order to launch some uwsgi service and how to setting nginx config file.
Would you give me an advice?
Thanks in advance.
uwsgi_p1.ini for my_project1
[uwsgi]
chdir = /root/my_workplace/my_project1
module = my_project1.wsgi
virtualenv = /root/my_workplace/virtual/my_project1
processes = 2
socket = 127.0.0.1:10001 # **pay attention to this port**
vacuum = true
master = true
nginx_p1.conf for my_project1
server {
listen 8888; # use different server_name or listenport
charset utf-8;
client_max_body_size 75M;
server_name project1.mydomain.com; # use different server_name or listenport
location / {
uwsgi_pass 127.0.0.1:10001; # pay attention to here
include uwsgi_params;
}
}
==============================
uwsgi_p2.ini for my_project2
[uwsgi]
chdir = /root/my_workplace/my_project2
module = my_project2.wsgi
virtualenv = /root/my_workplace/virtual/project2
processes = 2
socket = 127.0.0.1:10002
vacuum = true
master = true
nginx_p2.conf for my_project2
server {
listen 8889;
charset utf-8;
client_max_body_size 75M;
server_name project2.mydomain.com;
location / {
uwsgi_pass 127.0.0.1:10002;
include uwsgi_params;
}
}
and so on...
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.
-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.