更新於 2024/08/29閱讀時間約 3 分鐘

Django as a back-end web server in production feat. Nginx

Introduction

There are some differences between deploying a front-end framework project on the web server and deploying a back-end one.
Let’s take Vue and Nginx for instance. It’s very simple. Just bundle your Vue project and deploy it on Nginx.
For the python back-end, we need to set up the WSGI between the web server and application. In this article, I would use Nginx to deploy the web server, using uWSGI as WSGI, and using Django as the back-end application.

uWSGI

installation
We use uWSGI as the WSGI server for the python back-end. Just use pip to install it.
$ pip install uwsgi

uWSGI config
Let’s create a config file for uWSGI. It should include the ini file extension.
socket is where you want to deploy this uWSGI service. I think deploying it at localhost is fine. chdir is the path to your back-end project. module is a python script for the WSGI settings. For the Django project, there is already contain a wsgi.py located at back_end . chdir is the path to your python virtual environment.

run uWSGI server
$ uwsgi --ini /path-to-yourfile.ini

Nginx

For the config of this back-end
Include the uwsgi_params which is already located in the Nginx. Set uwsgi_pass equal to where you run your uWSGI service before.
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.