I have the following configuration:
[uwsgi]
vhost = true
plugins = python,logfile
socket = /tmp/mysite.com.sock
master = true
enable-threads = true
processes = 4
wsgi-file = /home/ubuntu/myappwebsite/myapp/myapp/wsgi.py
chdir = /home/ubuntu/myappwebsite/myapp
touch-reload = /home/ubuntu/myappwebsite/myapp/myapp/reload
logger=file:/tmp/uwsgi-error.log
vacuum = true
and for nginx:
server {
listen 80;
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite.com_access.log;
error_log /var/log/nginx/mysite.com_error.log;
client_max_body_size 75M;
location / {
uwsgi_pass unix:///tmp/mysite.com.sock;
include uwsgi_params;
}
}
When I look at the nginx logs i see the following:
2016/11/14 01:36:43 [error] 10779#10779: *9 connect() to unix:///tmp/mysite.com.sock failed (111: Connection refused) while connecting to upstream, client: 10.13.142.61, server: mysite.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/mysite.c
I'm getting the following in my uwsgi log file:
Mon Nov 14 02:08:22 2016 - unable to find logger file
I'm not able to find any issues in the uwsgi logs for some strange reason. Is there anything else i'm missing here? I'm using an EC2 with Ubuntu 16.04 if that helps. I have googled and reconfigured this from scratch again and still to no avail. Please, any help appreciated!
make sure the owner of the wsgi file is the same as nginx user.
chown www-data:www-data wsgi.py
Related
I'm trying to deploy a Django application on Ubuntu 16.4. I referred a document to deploy my application and here this is the URL which I have followed server-django-nginx-with-uwsgi.
Everything went good until I faced this issued.
*1 connect() to unix:/run/uwsgi/firstsitecd.sock failed (111: Connection refused) while connecting to upstream
My socket file location
/run/uwsgi/firstsitecd
permission provided for the socket file
f: /run/uwsgi/firstsitecd.sock
drwxr-xr-x root root /
drwxr-xr-x root root run
drwxr-xr-x iradmin www-data uwsgi
srwxrwxrwx root root firstsitecd.sock
/etc/uwsgi/sites/firstsitecd.ini
[uwsgi]
project = firstsitecd
uid = ******
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
In .ini I have tried with chmod-socket = 660 & chmod-socket = 666 but nothing helps me.
/etc/nginx/site-available/firsitecd
server {
listen 92;
server_name my_ubuntu_ip_address;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/******/firstsitecd;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/firstsitecd.sock;
}
}
I tired with plethora of suggestion but nothing helps.
Thanks
9 application integrated to nginx via uwsgi application on Centos7.
It was working fine, but then i had to reboot my machine. Now i am having the follwoing issue: unix:/socket/uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: 10.184.160.9, server: 10.184.2.231, request: "GET /", upstream: "uwsgi://unix:/socket/uwsgi.sock:" Any clue?
My ini file:
[uwsgi]
chdir = /home/elastic/workspace/ES_Brevetti
wsgi-file = ES_Brevetti/wsgi.py
master = true
processes = 5
uid = nginx
gid = nginx
socket = /socket/uwsgi.sock
chmod-socket = 666
vacuum = true
nginx.conf
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 /nuovopatentdb/static {
alias /home/elastic/workspace/ES_Brevetti/static;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:/socket/uwsgi.sock;
}
}
I dont know why i am having this issue?
Further mode should i be creating the sock file anytime the machine is rebooted ?
Thanx valerio
the solution is disabling SElinux "sudo setenforce Permissive".
Thank you very much
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.
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
I am using uWsgi to deploy my django site here is my uWsgi.ini:
[uwsgi]
socket=/var/run/uwsgi.sock
virtualenv=/root/edupalm/env/
chdir=/root/edupalm/edupalm
master=True
workers=8
pidfile=/var/run/uwsgi-master.pid
max-requests=5000
module=edupalm.wsgi:application
and using nginx, here is my configuration:
server {
listen 9000;
server_name 162.243.146.127;
access_log /var/log/nginx/edupalm_access.log;
error_log /var/log/nginx/edupalm_error.log;
location /static/ {
alias /root/edupalm/edupalm/static/;
}
location / {
uwsgi_pass unix:///var/run/uwsgi.sock;
}
}
but I am having 502 Bad Gateway
here is the logs:
nginx:
2013/11/26 08:31:09 [error] 1758#0: *57 upstream prematurely closed connection while reading response header from upstream, client: 197.160.112.183, server: 162.243.146.127, request: "GET /admin HTTP/1.1", upstream: "uwsgi://unix:///var/run/uwsgi.sock:", host: "162.243.146.127:9000"
uwsgi:
-- unavailable modifier requested: 0 --
nginx is running on user www-data and uwsgi is running as root
It's advisable to use new user for your project, not root
The problem is in configuration, you should to add
plugin=python
for permissions it's better to use www-data user/group:
uid = www-data
gid = www-data
chmod-socket = 777
chown-socket = www-data
It looks like you are using a distribution package instead of official uWSGI sources. Just load (after having installed it) the python plugin with plugin = python in your config
http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html
location / {
uwsgi_pass unix:///var/run/uwsgi.sock;
include uwsgi_params;
uwsgi_param SCRIPT_NAME '';
}
I similarly had this problem for a combination of Django, uWSGI and nginx running behind CloudFront. It turned out for me that the routing table in CloudFront didn't behave as expected, so some of the callbacks weren't received.
Specifically, route "/" stole traffic from "*".
There was another issue where my Django server was running unexpected code; as a user logging in caused their User model to be changed, which I hadn't predicted for some reason. So yeah, don't rule out that your Django server might be legitimately busy, causing a timeout of the socket.