采用 nginx + gunicorn + django部署,系统是centos7
nginx 安装
官网下载安装http://nginx.org/en/docs/
配置文件
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name youtubemp4.us;
charset utf-8;
client_max_body_size 10m;
access_log /var/log/nginx/build-access.log;
error_log /var/log/nginx/build-err.log;
location /static/ {
#静态文件如js,css的存放目录
alias /root/en7/static/;
}
location / {
proxy_pass http://0.0.0.0:8000; # 这里要配合启动文件使用
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
软连接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
命令
nginx -c xxx.conf
nginx -s reload
gunicorn
pip install gunicorn
配置文件
# /usr/bin/python3
# encoding: utf-8
import multiprocessing
bind = ‘0.0.0.0:8000‘ #绑定ip和端口号
backlog = 512 #监听队列
chdir = ‘/root/en7‘ #gunicorn要切换到的目的工作目录
timeout = 30 #超时
workers = multiprocessing.cpu_count() * 2 + 1 #进程数
threads = 2 #指定每个进程开启的线程数
# 设置守护进程
daemon = True
命令
gunicorn 模块名.wsgi:application -c xxx.conf
kill -9 pid
django
修改settings文件
DEBUG = False
ALLOWED_HOSTS = ["149.28.39.105","youtubemp4.us"]
STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘)
# STATICFILES_DIRS = [
# os.path.join(BASE_DIR,"static")
# ]
执行收集静态文件
python manager.py collectstatic
原文:https://www.cnblogs.com/huameixiao/p/13369186.html