zoukankan      html  css  js  c++  java
  • Django 部署

     mysql

    收集静态文件

     

    nginx配置

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user root;
    worker_processes 4;
    
    error_log /var/log/nginx/error.log;
    pid /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        #types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
        
        upstream django {
            # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
            server 127.0.0.1:8001; # for a web port socket (we'll use this first)
        }
        server {
            listen      80;
    
            #server_name ; 
            charset     utf-8;
    
            
            # max upload size
            client_max_body_size 75M;   # adjust to taste
    
            location /static {
                alias  /data/s4/deploy/uuuuuu; # your Django project's static files - amend as required
            }
    
            # Finally, send all non-media requests to the Django server.
            location / {
                uwsgi_pass  django;
                include     uwsgi_params; # the uwsgi_params file you installed
            }
        }
    }
    View Code
    Django部署:
        1. 租云服务器
        
        2. 买服务器
        
        
                租:公网IP,111.13.101.208
            租域名:www.pythonav.com <-> 111.13.101.208
        
        3. 编写代码
            
        
        4. 拷贝代码到服务器[Python,Django,pymysql,sqllite]
        
        
        5. 
            settings.py
                ALLOWED_HOSTS = ['服务器',]
            
            python manage.py runserver 0.0.0.0:8001
        
            使用:
                遵循wsig协议:
                    wsgiref
        6. uwsgi
            pip3 intall uwsgi 
            
            
            简单测试:
                app.py
                    def application(env, start_response):
                        start_response('200 OK', [('Content-Type','text/html')])
                        return [b"Hello World"]
                        
                uwsgi --http :9001 --wsgi-file app.py
    
                uwsgi --http :9002 --wsgi-file foobar.py --master --processes 4 --threads 2
                
            Django:
                
                # 不处理静态文件
                uwsgi --http :9002 --chdir /data/s4/deploy --wsgi-file deploy/wsgi.py --master --processes 4 --threads 2  
                
                
                
                STATICFILES_DIRS = (
                    os.path.join(BASE_DIR,'static'),
                )
                STATIC_ROOT = os.path.join(BASE_DIR,'uuuuuu')
                
                python manage.py collectstatic
                
                完事,注释静态配置
                
                # 处理静态文件
                uwsgi --http :9003 --chdir /data/s4/deploy --wsgi-file deploy/wsgi.py --static-map /static=/data/s4/deploy/uuuuuu
                
                
                # 写一个配置文件
                    wsgi_http.ini
                        [uwsgi]
                        http = 0.0.0.0:9004
                        chdir = /data/s4/deploy
                        wsgi-file = deploy/wsgi.py
                        # processes = 4
                        # threads = 2
                        static-map = /static=/data/s4/deploy/uuuuuu
                    uwsgi wsgi_http.ini
                    
        7. Nginx
            
            yum install nginx
            
            /etc/init.d/nginx start/stop/restart
            
            /etc/nginx/nginx.conf
            
            
            
            
            
            
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
                
                    
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
    View Code
    [uwsgi]
    socket = 127.0.0.1:8001
    chdir = /data/s4/deploy
    wsgi-file = deploy/wsgi.py
    # processes = 4
    # threads = 2
    static-map = /static=/data/s4/deploy/uuuuuu
    uwsgi

    bs4

    django

    Pillow
  • 相关阅读:
    Ubuntu安装Apache
    【C#设计模式——创建型模式】抽象工厂模式
    【C#设计模式——创建型模式】工场方法模式
    【C#设计模式——创建型模式】简单工场模式
    JS判断是不是Decimal类型(正则实现)
    JS实现给页面表单设置触发默认按钮
    记录ASP.NET页面表单初始状态(主要是为了前台可以根据这个判断页面是否变动了)
    Js触发ASP.NET Validation控件的验证, 同时获取前台验证结果(不包括CustomValidator)
    根据字段名查找表名
    SqlServer判断数据库、表、存储过程、函数是否存在
  • 原文地址:https://www.cnblogs.com/golangav/p/8560190.html
Copyright © 2011-2022 走看看