I've connected with flask, wsgi and apache2, but I've always hated Django. However, I decided to introduce Django and nginx because I wanted to introduce WebSocket and so on.
Even now, it is not displayed unless I enter ** "http://example.com:9000" **, but I have reached the point where uwsgi is started in the background.
I will write the part that I struggled with below
It was good until I started the nginx server
$sudo /etc/init.d/nginx restart
When I typed it, it sometimes failed to start. I got the following display
[....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
failed!
This was due to the wrong configuration file in ** / etc / nginx / sites-available / ** in my Ubuntu environment. (For example, the port was duplicated with another server)
This was the beginning of suffering. I was suffering from uwsgi and had a hard time. Above all, it is a failure to think that something can be done with glue.
Think of uwsgi as middleware that acts as an intermediary with settings to connect nginx and Django apps. How to paste my crappy ini file. By the way, I will also introduce the sites that were very helpful in uwsgi. (English)
Below are my ini files and their commentary.
# open_dashboard_uwsgi.ini file
[uwsgi]
project = open_dashboard
base = /home/user/Python #← Path of my Python project
chdir = %(base)/%(project)
#home = %(base)/Env/%(project)
home = %(base)/env #← Path of my Python virtual environment
module = %(project).wsgi:application
#uid = root
uid = user #← My user name
master = true
processes = 2
socket = %(base)/%(project)/%(project).sock #← Do not try to make this socket yourself
chmod-socket = 666
vacuum = true #← It is quite important that the socket is automatically deleted when the server is cut off.
Based on this, the emperor mode is set to the mode that runs uwsgi in the background (actually, it is a great mode that can start multiple apps), but in most cases it stumbles with the following error.
unix:///home/user/Python/open_dashboard/open_dashboard.sock failed (13: Permission denied)
This is annoying, but it can be resolved by using the emperor mode uid and gid as your username. Also the log file ** sudo chown user: user /var/log/uwsgi-emperor.log ** Don't forget to set such as.
Set .bashrc as follows. (/etc/rc.local seems to be good, but for the time being, the sure one)
.bashrc
/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data --daemonize /var/log/uwsgi-emperor.log
The *** --emperor / etc / uwsgi / vassals *** part of the above code is set as follows.
# create a directory for the vassals
sudo mkdir /etc/uwsgi
sudo mkdir /etc/uwsgi/vassals
# symlink from the default config directory to your config file
sudo ln -s /path/to/your/mysite/mysite_uwsgi.ini /etc/uwsgi/vassals/
-(Updated January 1, 2020) For users, www-data is good. Specify / tmp if no socket is created -(Updated January 1, 2020) If uwsgi of Python2, an error will occur in Python3, so you need to reinstall uwsgi with pip3 etc.
You may not understand it because you are in a hurry, but for the time being ** So that I don't get lost again ** I wrote this article.
[I was spending dark days with only 502 errors like this article](https://www.linode.com/community/questions/222/how-do-i-fix-this-502-bad- gateway-error-when-setting-up-django-project-on-ubuntu)
_ Next, I'm going to challenge Docker! _
--2019/12/16 Newly created --2020/1/1 Added how to install and reconfigure uwsgi for Python3 again when doing it with Python3
Recommended Posts