Django 와 uwsgi, nginx 와 함께 정적 캐 시 를 만 듭 니 다.

4804 단어
python-env
1, mysql
grant all on demo.* to demo@'127.0.0.1' identified by 'wd1023';
flush privileges;
create database demo character set = utf8;

2, nginx 와 초기 고장 스 크 립 트
# onestack   
wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ~/oneinstack/install.sh --nginx_option 1     

# python                                                        
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz && tar xvf Python-3.6.5.tar.xz && cd Python-3.6.5/     
./configure && make && make install             
mkdir -p /data/ && cd /data                         
python3.6 -m venv py36                          
source /data/py36/bin/activate

#     
unzip demo.zip 
mv demo wwwroot/project
cd /data/wwwroot/project/
apt install libmysqlclient-dev -y
pip install -r requirements.txt

3, Django 프로젝트 설정
vi demo/settings.py                             
ALLOWED_HOSTS = ['*']                               #        
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'demo',
        'USER':'demo',
        'PASSWORD':'wd1023',
        'HOST':'192.168.1.200'
        'PORT':'3306',
        'OPTIONS': MYSQL_DATABASE_OPTIONS,
    }
}                                                           
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')     #      

python manage.py collectstatic                      #          STATIC_ROOT

python manage.py makemigrations
python manage.py migrate                            #       
python manage.py createsuperuser                    #     
python manage.py runserver 0.0.0.0:8000             #    

4, uwsgi 관련 프로필 및 디 렉 터 리
mkdir /data/uwsgi-script -p                         #  uwsgi-script  log   (          )
chown www.www -R /data/wwwroot/project              #         uwsgi   
mkdir /etc/uwsgi/sites/ -p                          #  uwsgi         (   nginx conf/vhost  )
cat /etc/uwsgi/sites/demo.ini                       #     uwsgi  demo.ini
[uwsgi]
#socket = :8000                                 
uid = www
socket = /run/uwsgi/demo.sock                       # unix-socket  
chmod-socket = 660                                  #socket  
chown-socket = www:www                              #socket  
    
#http = 192.168.1.210:8000
static-map=/static=/data/wwwroot/project/static/    #       setting  STATIC_ROOT  
chdir = /data/wwwroot/project/                      #     
module = demo.wsgi:application                      #   app  wsgi  (  uwsgi     wsgi)
home = /data/py36                                   #       
pidfile = /data/uwsgi-script/demo/uwsgi.pid         #pid  
daemonize = /data/uwsgi-script/demo/uwsgi.log       #    
master = true                                       
processes = 3                                       #      
threads = 2
vacuum = true                                       #      ,    emperor  
max-requests = 2000

PS: 생 성하 지 않 으 면 mkdir / data / uwsgi - script / demo / touch / data / uwsgi - script / demo / uwsgi. log 오류 가 발생 합 니 다.
5, nginx 관련 설정
mkdir /usr/local/nginx/conf/vhost
vi /usr/local/nginx/conf/vhost/demo.conf
server {
    listen 80;
    server_name _;
    access_log      /data/wwwlogs/demo_nginx_access.log;
    client_max_body_size 75M;
    charset utf-8;
    gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;
    location /static {                                  #nginx  uwsgi        
        alias /data/wwwroot/project/static/;
    }

    location / {
        include uwsgi_params;
#        uwsgi_pass 127.0.0.1:8000;
        uwsgi_pass unix:/run/uwsgi/demo.sock;           #nginx  uwsgi unix-socket
    }
}

vi /usr/local/nginx/conf/nginx.conf   #       default server 
:61,92 s/^/#/g

nginx -t
nginx -s reload

6, systemcd 스 크 립 트
cat /lib/systemd/system/demo.service
[Unit]
Description=uWSGI Emperor service

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown www.www /run/uwsgi'
ExecStart=/data/py36/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

systemctl enable demo

7, uwsgi 테스트 명령
시작: uwsgi -- ini yourpath / demo. ini 정지: uwsgi -- stop yourpath / uwsgi. pid 재 부팅: uwsgi -- reload yourpath/uwsgi.pid
다음으로 전송:https://www.cnblogs.com/ops-sylar/p/8984629.html

좋은 웹페이지 즐겨찾기