标签:cat 结束 err 部署 ons send turn pytho connect
一. uwsgi
1. 安装
pip3 install uwsgi
2. 检验
def application(env, start_response): start_response(‘200 OK‘, [(‘Content-Type‘,‘text/html‘)]) return [b"Hello World"]
uwsgi --http 0.0.0.0:8000 --wsgi-file testTask/tests.py
打开浏览器http://127.0.0.1:8000/
uwsgi --http :8000 --file dj_test/wsgi.py
3. 配置uwsgi.ini
[uwsgi]
http = :9000
socket = 127.0.0.1:8001
chdir = /Users/conan/vir_env/AutoTest
wsgi-file = /Users/conan/vir_env/AutoTest/AutoTest/wsgi.py
module = AutoTest.wsgi:application
master = true
processes = 4
threads = 2
chmod-socket=664
vacuum=true
daemonize = /Users/conan/vir_env/AutoTest/uwsgi.log
参数解释:
二. nginx
1. 安装
brew install nginx
nginx -v # 查看安装版本号
nginx -t # 安装路径
2. 配置nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 127.0.0.1;
charset utf-8;
access_log /Users/zd/Documents/AutoTest/nginx_access.log;
error_log /Users/zd/Documents/AutoTest/nginx_error.log;
client_max_body_size 75M;
location /static {
alias /Users/zd/Documents/AutoTest/static;
}
location / {
root /Users/zd/Documents/AutoTest;
include /usr/local/etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
}
}
include servers/*;
}
3. 启动,重启,关闭
# 找nginx 安装路径 which nginx cd /usr/local/bin/nginx #重启 nginx -s reload #关闭 nginx -s stop. 或者 kill -9 nginx #是否关闭 ps aux|grep nginx
三. uwsgi+nginx 启动Django项目
1 nginx -t 2 cd /usr/local/etc/nginx 3 把mime.types 文件copy到django 项目与manage.py 同一级
1 uwsgi --ini uwsgi.ini 2 sudo nginx -c nginx.conf #根据报错信息,缺啥文件补充啥,补完之后,重复该命令
浏览器访问:127.0.0.1:9000/index/
四. 加载静态资源
在Django setting.py里加
STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘)
终端执行命令
python3 manage.py collectstatic #收集静态文件
url.py(例如:AutoTest/AutoTest/url.py)
1 from django.conf import settings 2 urlpatterns = [ 3 url(r‘^admin/‘, include(admin.site.urls)), 4 url(r‘‘, include(‘testTask.urls‘)), 5 url(r‘^static/(?P<path>.*)$‘, ‘django.views.static.serve‘, { ‘document_root‘: settings.STATIC_ROOT,}), 8 ]
mac+django(1.8.2)+uwsgi+nginx 部署
标签:cat 结束 err 部署 ons send turn pytho connect
原文地址:https://www.cnblogs.com/zhang-dan/p/11603844.html