nginx+uwsgi+django is our commonly used Django deployment method. As the front-end server, nginx is responsible for receiving all client requests. The requested static files are processed by the nginx server itself because it has a good ability to handle static files, has optimized performance, and supports high concurrency. The uWSGI server is a support server that is used to serve nginx. nginx hands the requested dynamic files to uWSGI for processing. uWSGI implements the uwsgi, wsgi and http protocols. The uwsgi protocol is a custom protocol of uWSGI, which defines the interface between the framework (django) and the server. 1. Install the project environment System environment: Ubuntu 16.04 Python environment: python3.5.2 Django version: django1.11.7 Nginx environment: nginx_1.10.3 Virtual environment: virtualenv15.1.0 uwsgi version: uwsgi2.0.17.1 Install and enter the project virtual environment: sudo apt-get install virtualenv virtualenv -p python3 env_my_project source env_my_project/bin/activate pip install -r requirements.txt 2. Project configuration and operation test Modify the project configuration file: cp my_project/settings_local.py.example my_project/settings_local.py Modify the es configuration file: cp rs_es/es_settings.py.example rs_es/es_settings.py wsgi.py: import os from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings_local") application = get_wsgi_application() Project running test: python manage.py collectstatic # Collect static files python manage.py makemigrations python manage.py migrate python manage.py runserver 0.0.0.0:8001 3. NGINX and UWSGI related configuration sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/my_project sudo ln -s /etc/nginx/sites-available/my_project /etc/nginx/sites-enabled/ sudo vim /etc/nginx/sites-enabled/my_project nginx configuration: upstream my_project{ server unix:///var/run/my_project.sock; } server { listen 8001; //The service port number service is started through nginx and uwsgi communication server_name 192.168.xx.xx; //The ip of nginx proxy charset utf-8; # max upload size client_max_body_size 10M; # send all non-media requests to the Django server. location / { uwsgi_pass my_project; include /etc/nginx/uwsgi_params; } location /static/ { root /home/ubuntu/my_project; } } Uwsgi configuration: sudo mkdir /var/log/uwsgi sudo chmod -R 777 /var/log/uwsgi uwsgi.ini: [uwsgi] chdir=/home/ubuntu/my_project home=/home/ubuntu/my_project/env_my_project module=my_project.wsgi:application socket=/var/run/my_project.sock chmod-socket = 666 master=True processes = 5 max-requests=5000 # clear environment on exit vacuum=True pidfile=/var/run/my_project.pid daemonize=/var/log/uwsgi/my_project.log # git pull automatically restarts the service touch-reload=.git/index 4. Configure Emperor mode monitoring and system automatic startup of uwsgi Configure Emperor mode listening sudo mkdir /etc/uwsgi sudo mkdir /etc/uwsgi/vassals sudo ln -s /home/ubuntu/my_project/uwsgi.ini /etc/uwsgi/vassals/ The system automatically starts uwsgi sudo vim /etc/rc.local /usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals 5. Start Django service through uwsgi Start uwsgi uwsgi --ini uwsgi.ini Restart nginx sudo service nginx restart Start the Django service sudo uwsgi --reload /var/run/my_project.pid At this point, you can access the service through the ip and port proxy from ngnix in the browser The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Vue implements a visual drag page editor
>>: MySQL 5.7.11 zip installation and configuration method graphic tutorial
1. Check the MySQL database encoding mysql -u use...
Copy code The code is as follows: <!DOCTYPE ht...
How to install Linux CentOS 7.7 system in Vmware,...
The effect is as follows: Example 1 Example 2: Ta...
Apache Superset is a powerful BI tool that provid...
This article shares the specific code for JavaScr...
This article shares the specific code of jQuery t...
Install Nginx on Docker Nginx is a high-performan...
Table of contents Setting up a basic HTTP request...
I recently joined a new company and found some mi...
This article shares the specific code for JavaScr...
Table of contents 1. Definition and Use 1.1 Defin...
Introduction When writing SQL today, I encountere...
There are two ways to delete data in MySQL: Trunc...
1 Check whether the kernel has a tun module modin...