{"id":319488,"date":"2021-03-12T21:00:18","date_gmt":"2021-03-12T21:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=319488"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=319488","title":{"rendered":"\u0417\u0430\u043f\u0443\u0441\u043a Django \u0441\u0430\u0439\u0442\u0430 \u043d\u0430 nginx + Gunicorn + SSL"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443\u0448\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u0438\u043b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u042f \u043d\u0430\u0442\u044b\u043a\u0430\u043b\u0441\u044f \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043a\u0430\u043a \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u0442\u0430\u043a \u0438 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0430\u0445, \u043d\u043e \u043a\u0430\u043a \u044f \u043f\u043e\u043d\u044f\u043b, &#8212; \u043e\u043d\u0438 \u0432\u0441\u0435 \u0431\u044b\u043b\u0438 \u043a\u043b\u043e\u043d\u0430\u043c\u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 Digital Ocean. \u0421\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b, \u043f\u043e\u0447\u0435\u043c\u0443 \u044f \u0442\u0430\u043a \u0441\u0447\u0438\u0442\u0430\u044e, \u0430 \u0432\u0441\u0435 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u0441\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.  <\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 VPS c \u041e\u0421 Ubuntu, \u0438 \u043c\u044b \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 PyCharm \u0438\u043b\u0438 \u0432 \u0431\u043b\u043e\u043a\u043d\u043e\u0442\u0435 \u0441\u0432\u043e\u0439 \u0441\u0430\u0439\u0442 \u043d\u0430 Django \u0438 \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0434\u043e\u043c\u0435\u043d, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438 \u0432 \u043f\u0443\u0442\u044c.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0430\u043a\u0435\u0442 nginx:<\/p>\n<pre><code class=\"bash\">apt get update apt get-install nginx<\/code><\/pre>\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u0430\u0439\u0442\u0430 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435: \/var\/www\/. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433&nbsp;<em>cd \/var\/www\/<\/em>&nbsp;\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433&nbsp;<em>mkdir geekhero<\/em>&nbsp;\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0443\u0442\u044c: \/var\/www\/geekhero\/<\/p>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u043e\u0432\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 geekhero:&nbsp;<em>cd geekhero<\/em>&nbsp;\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:&nbsp;<em>python3 -m venv geekhero_env<\/em><\/p>\n<p>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:&nbsp;<em>source geekhero_env\/bin\/activate&nbsp;<\/em>\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u0433\u043e Django: pip install Django \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0441\u0442\u0430\u0432\u0438\u043c pip install gunicorn<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442:&nbsp;<code>django-admin startproject ghproj<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438; \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c:&nbsp;<code>python manage.py makemigrations<\/code>&nbsp; , \u0437\u0430\u0442\u0435\u043c&nbsp;<code>python manage.py migrate<\/code>&nbsp; .<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u0443\u0447\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c: <code>python manage.py createsuperuser<\/code> \u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c applications, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b \u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u0442\u0435 \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 <u>Settings.py<\/u> \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c, \u0435\u0441\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442:<br \/><code>import os<\/code> \u2013 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0438\u0437\u0443 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<\/p>\n<pre><code class=\"python\">STATIC_URL = '\/static\/' STATIC_ROOT = os.path.join(BASE_DIR, 'static\/')<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430&nbsp;Gunicorn<\/h2>\n<p>\u0418\u0434\u0435\u043c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <u>\/etc\/systemd\/system\/<\/u> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u0444\u0430\u0439\u043b\u0430: <u>gunicorn.service<\/u> \u0438 <u>gunicon.socket<\/u>:  <\/p>\n<p><em>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 gunicorn.service:<\/em><\/p>\n<pre><code class=\"bash\">[Unit] Description=gunicorn daemon Requires=gunicorn.socket After=network.target  [Service] User=root WorkingDirectory=\/var\/www\/geekhero #\u043f\u0443\u0442\u044c \u0434\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441 \u0444\u0430\u0439\u043b\u043e\u043c manage.py ExecStart=\/var\/www\/geekhero\/geekhero_env\/bin\/gunicorn --workers 5 --bind unix:\/run\/gunicorn.sock ghproj.wsgi:application #\u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430 gunicorn \u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438  [Install] WantedBy=multi-user.target<\/code><\/pre>\n<p><em>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 gunicorn.socket:<\/em><\/p>\n<pre><code class=\"bash\">[Unit] Description=gunicorn socket  [Socket] ListenStream=\/run\/gunicorn.sock  [Install] WantedBy=sockets.target<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 gunicorn.service \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<pre><code>systemd-analyze verify gunicorn.service<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 NGINX<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u043c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433: <u>\/etc\/nginx\/sites-available\/<\/u> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b geekhero (\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430) \u0431\u0435\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"nginx\">server {     listen 80;     server_name example.com;          location = \/favicon.ico { access_log off; log_not_found off; }     location \/static\/ {         root \/var\/www\/geekhero;           #\u043f\u0443\u0442\u044c \u0434\u043e static \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430     }          location \/media\/ {         root \/var\/www\/geekhero;           #\u043f\u0443\u0442\u044c \u0434\u043e media \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430     }          location \/ {         include proxy_params;         proxy_pass http:\/\/unix:\/run\/gunicorn.sock;     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0444\u0430\u0439\u043b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435<em>&nbsp;<u>\/etc\/nginx\/site-enabled\/<\/u><\/em>&nbsp;\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>sudo ln -s \/etc\/nginx\/sites-available\/geekhero \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u044f\u0440\u043b\u044b\u043a \u0438\u0437 <u>sites-enabled<\/u> \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u0432\u044b\u0448\u0435 \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:&nbsp;<code>sudo systemctl restart nginx<\/code><\/p>\n<h2>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0442\u0430\u043f<\/h2>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 nginx \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p><code>sudo nginx -t<\/code>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043b\u0443\u0436\u0431\u0443 gunicorn \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c socket:<\/p>\n<pre><code>sudo systemctl enable gunicorn sudo systemctl start gunicorn<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p><em>sudo systemctl disable gunicorn<br \/>sudo systemctl stop gunicorn<\/em><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435, \u044d\u0442\u0438 \u043e\u0431\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 HTML \u0438\u043b\u0438 python \u0444\u0430\u0439\u043b\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0430\u0439\u0442, \u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u043d\u043e\u0441\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c python manage.py&nbsp;makemigrations &lt;app&gt; \u0438 migrate &lt;app&gt; \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \/ \u043f\u043e\u043b\u043d\u043e\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 Gunicorn:&nbsp;<br \/><code>service gunicorn start \/ service gunicorn stop<\/code><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">sudo systemctl status gunicorn \u0438\u043b\u0438 sudo journalctl -u gunicorn.socket (\u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u043a\u043e\u0439: \u043c\u0430\u0440 05 16:40:19 byfe systemd[1]: Listening on gunicorn socket. )<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>file \/run\/gunicorn.sock<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u044b\u0432\u043e\u0434 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c:&nbsp;\/run\/gunicorn.sock: socket<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043d\u0435\u0441 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b gunicorn.service \u0438\u043b\u0438 .socket, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>systemctl daemon-reload<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c nginx:<\/p>\n<pre><code>sudo service nginx start<\/code><\/pre>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 SSL \u0434\u043b\u044f \u0434\u043e\u043c\u0435\u043d\u0430<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c certbot \u043e\u0442 Let&#8217;s Encrypt:&nbsp;<code>sudo apt-get install certbot python-certbot-nginx<\/code><\/p>\n<p>\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>certbot:&nbsp;sudo certbot certonly --nginx<\/code><\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e nginx:&nbsp;<code>sudo certbot install --nginx<\/code><\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 nginx:&nbsp;<code>sudo systemctl restart nginx<\/code><\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u043a\u0430\u043a \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0448 \u0441\u0430\u0439\u0442 \u0432 production, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 Django, Gunicorn, nginx \u0438 \u0434\u0430\u0436\u0435 certbot \u043e\u0442 Let&#8217;s Encrypt.  <\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/546778\/\"> https:\/\/habr.com\/ru\/post\/546778\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443\u0448\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u0438\u043b \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u042f \u043d\u0430\u0442\u044b\u043a\u0430\u043b\u0441\u044f \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043a\u0430\u043a \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u0442\u0430\u043a \u0438 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0430\u0445, \u043d\u043e \u043a\u0430\u043a \u044f \u043f\u043e\u043d\u044f\u043b, &#8212; \u043e\u043d\u0438 \u0432\u0441\u0435 \u0431\u044b\u043b\u0438 \u043a\u043b\u043e\u043d\u0430\u043c\u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 Digital Ocean. \u0421\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b, \u043f\u043e\u0447\u0435\u043c\u0443 \u044f \u0442\u0430\u043a \u0441\u0447\u0438\u0442\u0430\u044e, \u0430 \u0432\u0441\u0435 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u0441\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.  <\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 VPS c \u041e\u0421 Ubuntu, \u0438 \u043c\u044b \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0432 PyCharm \u0438\u043b\u0438 \u0432 \u0431\u043b\u043e\u043a\u043d\u043e\u0442\u0435 \u0441\u0432\u043e\u0439 \u0441\u0430\u0439\u0442 \u043d\u0430 Django \u0438 \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0434\u043e\u043c\u0435\u043d, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0438 \u0432 \u043f\u0443\u0442\u044c.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0430\u043a\u0435\u0442 nginx:<\/p>\n<pre><code class=\"bash\">apt get update apt get-install nginx<\/code><\/pre>\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u0430\u0439\u0442\u0430 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435: \/var\/www\/. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433&nbsp;<em>cd \/var\/www\/<\/em>&nbsp;\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433&nbsp;<em>mkdir geekhero<\/em>&nbsp;\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u0443\u0442\u044c: \/var\/www\/geekhero\/<\/p>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u043d\u043e\u0432\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 geekhero:&nbsp;<em>cd geekhero<\/em>&nbsp;\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:&nbsp;<em>python3 -m venv geekhero_env<\/em><\/p>\n<p>\u0410\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435:&nbsp;<em>source geekhero_env\/bin\/activate&nbsp;<\/em>\u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u0433\u043e Django: pip install Django \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0441\u0442\u0430\u0432\u0438\u043c pip install gunicorn<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442:&nbsp;<code>django-admin startproject ghproj<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438; \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c:&nbsp;<code>python manage.py makemigrations<\/code>&nbsp; , \u0437\u0430\u0442\u0435\u043c&nbsp;<code>python manage.py migrate<\/code>&nbsp; .<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u0443\u0447\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c: <code>python manage.py createsuperuser<\/code> \u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c applications, \u043d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b \u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u0442\u0435 \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u0432 <u>Settings.py<\/u> \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c, \u0435\u0441\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442:<br \/><code>import os<\/code> \u2013 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0438\u0437\u0443 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<\/p>\n<pre><code class=\"python\">STATIC_URL = '\/static\/' STATIC_ROOT = os.path.join(BASE_DIR, 'static\/')<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430&nbsp;Gunicorn<\/h2>\n<p>\u0418\u0434\u0435\u043c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <u>\/etc\/systemd\/system\/<\/u> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u0444\u0430\u0439\u043b\u0430: <u>gunicorn.service<\/u> \u0438 <u>gunicon.socket<\/u>:  <\/p>\n<p><em>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 gunicorn.service:<\/em><\/p>\n<pre><code class=\"bash\">[Unit] Description=gunicorn daemon Requires=gunicorn.socket After=network.target  [Service] User=root WorkingDirectory=\/var\/www\/geekhero #\u043f\u0443\u0442\u044c \u0434\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441 \u0444\u0430\u0439\u043b\u043e\u043c manage.py ExecStart=\/var\/www\/geekhero\/geekhero_env\/bin\/gunicorn --workers 5 --bind unix:\/run\/gunicorn.sock ghproj.wsgi:application #\u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430 gunicorn \u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438  [Install] WantedBy=multi-user.target<\/code><\/pre>\n<p><em>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 gunicorn.socket:<\/em><\/p>\n<pre><code class=\"bash\">[Unit] Description=gunicorn socket  [Socket] ListenStream=\/run\/gunicorn.sock  [Install] WantedBy=sockets.target<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 gunicorn.service \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<pre><code>systemd-analyze verify gunicorn.service<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 NGINX<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u043c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433: <u>\/etc\/nginx\/sites-available\/<\/u> \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b geekhero (\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430) \u0431\u0435\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"nginx\">server {     listen 80;     server_name example.com;          location = \/favicon.ico { access_log off; log_not_found off; }     location \/static\/ {         root \/var\/www\/geekhero;           #\u043f\u0443\u0442\u044c \u0434\u043e static \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430     }          location \/media\/ {         root \/var\/www\/geekhero;           #\u043f\u0443\u0442\u044c \u0434\u043e media \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430     }          location \/ {         include proxy_params;         proxy_pass http:\/\/unix:\/run\/gunicorn.sock;     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0444\u0430\u0439\u043b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435<em>&nbsp;<u>\/etc\/nginx\/site-enabled\/<\/u><\/em>&nbsp;\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>sudo ln -s \/etc\/nginx\/sites-available\/geekhero \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043b\u044e\u0431\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u044f\u0440\u043b\u044b\u043a \u0438\u0437 <u>sites-enabled<\/u> \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u0432\u044b\u0448\u0435 \u0438\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:&nbsp;<code>sudo systemctl restart nginx<\/code><\/p>\n<h2>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0442\u0430\u043f<\/h2>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 nginx \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p><code>sudo nginx -t<\/code>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043b\u0443\u0436\u0431\u0443 gunicorn \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c socket:<\/p>\n<pre><code>sudo systemctl enable gunicorn sudo systemctl start gunicorn<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p><em>sudo systemctl disable gunicorn<br \/>sudo systemctl stop gunicorn<\/em><\/p>\n<p>\u0422\u0430\u043a\u0436\u0435, \u044d\u0442\u0438 \u043e\u0431\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 HTML \u0438\u043b\u0438 python \u0444\u0430\u0439\u043b\u044b, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u0430\u0439\u0442, \u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u043d\u043e\u0441\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c python manage.py&nbsp;makemigrations &lt;app&gt; \u0438 migrate &lt;app&gt; \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \/ \u043f\u043e\u043b\u043d\u043e\u0439 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 Gunicorn:&nbsp;<br \/><code>service gunicorn start \/ service gunicorn stop<\/code><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u0432\u0432\u0435\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">sudo systemctl status gunicorn \u0438\u043b\u0438 sudo journalctl -u gunicorn.socket (\u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0442\u0430\u043a\u043e\u0439: \u043c\u0430\u0440 05 16:40:19 byfe systemd[1]: Listening on gunicorn socket. )<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>file \/run\/gunicorn.sock<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u044b\u0432\u043e\u0434 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c:&nbsp;\/run\/gunicorn.sock: socket<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u043d\u0435\u0441 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b gunicorn.service \u0438\u043b\u0438 .socket, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>systemctl daemon-reload<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c nginx:<\/p>\n<pre><code>sudo service nginx start<\/code><\/pre>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 SSL \u0434\u043b\u044f \u0434\u043e\u043c\u0435\u043d\u0430<\/h2>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c certbot \u043e\u0442 Let&#8217;s Encrypt:&nbsp;<code>sudo apt-get install certbot python-certbot-nginx<\/code><\/p>\n<p>\u041f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>certbot:&nbsp;sudo certbot certonly --nginx<\/code><\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e nginx:&nbsp;<code>sudo certbot install --nginx<\/code><\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 nginx:&nbsp;<code>sudo systemctl restart nginx<\/code><\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u043a\u0430\u043a \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0448 \u0441\u0430\u0439\u0442 \u0432 production, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 Django, Gunicorn, nginx \u0438 \u0434\u0430\u0436\u0435 certbot \u043e\u0442 Let&#8217;s Encrypt.  <\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/546778\/\"> https:\/\/habr.com\/ru\/post\/546778\/<\/a><br \/><\/br><\/br><\/p>\n<\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-319488","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319488"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319488\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}