1👍
I have the same problem, .sock
doesn’t create. This method helps me.
Prerequests:
- Installed nginx: when you type in browser 127.0.0.1 – obtain “Wellcome to nginx…”.
- You install python2 or 3 no matter, and other stuffs: pip, django, gunicorn…
- You installed and settled virtualenv. (in my case, I use virtualenvwrapper – this is good staffs, saves all you env in one folder:
/home/user/.virtualenvs/
) - You created django project, and when: python manage.py runserver –
you obtain “It works…” – this good news. - When you type gunicorn
--bind 0.0.0.0:8000 myproject.wsgi:application
– you have the same result, as a step 4.
Next step for setting you dj.project throgh gunicorn to nginx:
- You create file in
/etc/systemd/system/any_file_name.service
– you can named this file as you want, at DO – it names asgunicorn.service
.
my method:
$cd /etc/systemd/system
$sudo touch gunicorn.service
and open it your favorite text editor
$sudo subl gunicorn.service
- Inside it you write:
[Unit] Description=gunicorn daemon After=network.target [Service] User=vetal Group=www-data WorkingDirectory=/var/www/apple.net ExecStart=/home/vetal/.virtualenvs/univ/bin/gunicorn --workers 3 --bind unix:/var/www/apple.net/mysite/mysite.sock mysite.wsgi:application [Install] WantedBy=multi-user.target
ExecStart – what will be started by nginx, when your virualenv will be turned off. Do you remember, gunicorn was install through pip, when your env was turn on ?
— bind unix:… – this address WHERE your .sock will created! Pay attention for this!
CHECK EVERY LETTER!TWISE!!! (of course with you links..)
- Type:
$ls -l
if you see in attributes to your ‘gunicorn.service’ something:
-rw-r--r-- 1 root root 0 Янв 12 11:48 gunicorn.service
this means – this file is not executable, and you .sock
– file will never created! Make next:
$sudo chmod 755 gunicorn.service
and check:
$ls -l
if you get:
-rwxr-xr-x 1 root root 305 Янв 11 19:48 gunicorn.service
this good! Everything allright!
- Then you created nginx block, in /etc/nginx/site-available/ it likes next:
server { listen 80; root /var/www/apple.net; server_name apple.net; location = /favicon.ico { access_log off; log_not_found off; } location = /static/ { alias /var/www/apple.net/static/; } location / { include proxy_params; proxy_pass http://unix:/var/www/apple.net/mysite/mysite.sock; } }
Notice: proxy_pass – must be identicaly correct with folder where .sock
file created in gunicorn.service!
-
Copies this file to
/sites-enable
$ sudo cp /etc/nginx/site-avaliable/apple.net /etc/nginx/site-enable
-
I don’t have any domaine, so I modify my
/etc/hosts
file, add row:
127.0.0.10 apple.net
- Very important steps!!!
$pkill gunicorn
– this step kill daemon, which you may started before. gunicorn in this case, means name of file which you created before with .service extention, in /etc/systemd/system
– folder.
- Start gunicorn.service daemon:
$sudo systemctl start gunicorn $sudo systemctl enable gunicorn
- Start(or restart nginx)
$sudo /etc/init.d/nginx (re)start
- Check your domane name in browser.
0👍
Since gunicorn is running on a socket, you need to bind to that socket, not to a port, in the upstream section.
upstream mydomain_server {
server unix:/home/django/mydomain/run/gunicorn.sock fail_timeout=0;
}
- Django – Access Parent Model field when creating many-to-one model
- Update Form with Django from GET value
- ImproperlyConfigured MySQL in Django
- Passing multiple variables from the template to a view
0👍
I have nginx serving up a .sock file from gunicorn. My typical gunicorn call looks like this:
exec gunicorn \
--pid /web/gunicorn.pid \
--workers '4' \
--name myapp \
--chdir /src/myapp \
--bind unix:/web/.sock \
--log-file=- \
myapp.wsgi:application
My nginx conf for /
looks like this; the main difference seems to be that your proxy_pass statement doesn’t point to the .sock file:
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/web/.sock;
}
- Error to execute djangocms -f -p . mysite
- HTML/JS/Django Hiding incompatible options from two picklists