nginx + uwsgi + django open uwsgi_params failed (13: permission denied) - django

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.

Related

Can I run 3 uwsgi service using different port

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...

django nginx uwsgi not working

i ve created a django application not using virtual environment. I ve installed nginx and trying to integrate them via uwsgi application.
Here my configurations files.
[uwsgi]
chdir = /home/elastic/workspace/ES_Brevetti
wsgi-file = ES_Brevetti/wsgi.py
master = true
processes = 5
uid = nginx
gid = nginx
socket = unix:///socket/uwsgi.sock
chmod-socket = 666
vacuum = true
i've created the file /sockect/uwsgi.sock with permission 777
chown nginx:nginx -R /sockect/uwsgi.sock
and below nginx conf file:
upstream django {
server unix:///socket/uwsgi.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
listen 80;
server_name 10.184.2.231;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
charset utf-8;
location /static/ {
alias /home/elastic/workspace/ES_Brevetti;
}
location / {
include uwsgi_params;
uwsgi_pass unix:///socket/uwsgi.sock;
}
}
When i launch "systemctl start nginx" nginx is started with error:
connect() to unix:///socket/uwsgi.sock failed (111: Connection refused) while connecting to upstream,
When i run uwsgi --ini /etc/uwsgi/sites/ES_Brevetti.ini it doesnt run with error:
.....
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
bind(): Permission denied [core/socket.c line 230]
What i am doing wrong? On google i can only see configurations with VENV while i am not using virtual environment.
The docs (which I'm guessing you were following) suggest that the socket configuration option in your uwsgi ini file should take a path to the socket, not a URL. Could you try changing:
[uwsgi]
...
socket = unix:///socket/uwsgi.sock
to
[uwsgi]
...
socket = /socket/uwsgi.sock
The solution was change the socket = unix:///socket/uwsgi.sock to socket = /socket/uwsgi.sock in the uwsgi.ini file. I dont know why in some doc it appears the double slash for escaping.

Django + uWSGI + nginx 502 Internal Error (Permission Denied)

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.

Permission denied Accessing static files Nginx +uwsgi +Django

I have setup Django project on CentOS 6.5 with Nginx and uwsgi.
I am Getting error while accessing static content as below (/var/log/nginx/error.log)-
2015/11/02 19:05:37 [error] 29701#0: *52 open() "/home/amar/workspace/myproj/config/static/rest_framework/js/default.js" failed (13: Permission denied), client: 172.29.100.104, server: myapi.dev, request: "GET /static/rest_framework/js/default.js HTTP/1.1", host: "myapi.dev", referrer: "http://myapi.dev/api/v1/datasets/"
My /etc/nginx/conf.d/virtual.conf is as shown below -
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/uwsgi.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
#
#API
#
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name myapi.dev; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /static {
autoindex on;
alias /home/amar/workspace/myproj/config/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 /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
Here is my uwsgi.ini file :
[uwsgi]
chdir = /home/amar/workspace/myproj
#home = %(base)/.virtualenvs/myproj
module = config.wsgi:application
home = /home/amar/.virtualenvs/myproj
master = true
processes = 3
socket = /tmp/uwsgi.sock
chmod-socket = 777
vacuum = true
Could someone point me in the right direction?
It took time but I've fixed the problem myself. Changed the user from amar to root and set static folder permission to 666. Hope it helps someone in future.
Probably related to SELinux. You will need to allow HTTPD scripts and modules to connect to the network.
setsebool httpd_can_network_connect on -P

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