django nginx configuration of

django

When the introduction of third-party modules ensure high availability services, to set up a backup interface when the primary interface is down a supermarket can set parameters to use the interface backup.

nginx

  • Reverse proxy, web server, load balancing
  • Basic Commands
    • sudo nginx start
    • sudo nginx -s stop
    • sudo nginx -s quit
    • sudo nginx -s reopen
  • The key configuration module

    • Domain configuration events: network connection configuration (I / O modules)
    • server configuration Domain: Services Node Configuration
    • location
    • http domain configuration
    • upstream configure a domain: Domain reverse proxy configuration
  • Hierarchical relationship

    events {
      ....
    }
    http {
      ...
      upstream {
          ...
      }
      server {
          ...
          location {
              ...
          }
      }
    }

WSGI Protocol: web server and the web application specification communications

uwsgi: webserver accept client requests sent to the web application

web application :django flask tornado

django uwsgi department

  1. uWSGI can be multi-thread scheduling, process monitoring
  2. Provide a sound request log processing
  3. runserver poor performance

Why have uwsgi also use nginx

  • nginx provides a more secure service guarantee
  • Provide reverse proxy, load balancing and other functions
  • For static file handling capability

nginx configuration steps

  1. uwsgi start django application services

  2. Modify nginx reverse proxy configuration complete profile

    /etc/nginx/sites-available/nginx.conf backup

    upstream uwsgi {
     server 127.0.0.1:8000;
    }
    
    server {
     listen:80;
     server_name: .xxxxx.com 无论一级域名还是二级域名
     charset:utf-8;
    
     access_log # 可以配置日志文件
    
     location / {
         proxy_pass http://uwsgi;   # 所有访问域名的连接转发到配置好的upstream 
     }
    }

    Delete source /nginx.conf new configuration settings to conf soft connection

  3. Collect static files, complete static addressing configuration file

    设置好static_url 
    python manage.py collect

    Copy the directory generated

    server {
     listen:80;
     server_name: .xxxxx.com 无论一级域名还是二级域名
     charset:utf-8;
    
     access_log # 可以配置日志文件
    
     location / {
         proxy_pass http://uwsgi;   # 所有访问域名的连接转发到配置好的upstream 
     }
    
     location /static {
         alias 拷贝好的目录
     }
    }

    nginx -s reload

https deployment, you can apply for a personal domain free https Tencent cloud, configure the server certificate

Load balancing reverse proxy upstream, configuration weights, good upstream directly configure weights weight in each configuration. Close access uwsgi port.

Guess you like

Origin www.cnblogs.com/jimmyhe/p/11260509.html