centos+nginx+uwsgi+django

安装python环境

项目文件放到/opt/proj/中

进入/opt/proj/ApiAutomation

保障python manage.py runserver 0.0.0.0:8090可以运行

 

安装uwsgi

命令测试uwsgi可以运行项目

uwsgi --http :8000 --module ApiAutomation.wsgi --static-map=/static=static

在ApiAutomation同级目录下创建script文件夹

script里面创建uwsgi.ini文件

# uwsig使用配置文件启动
[uwsgi]
chdir=/opt/proj/ApiAutomation/
module=ApiAutomation.wsgi:application
#module=/opt/proj/ApiAutomation/ApiAutomation/wsgi.py     
socket=/opt/proj/script/uwsgi.sock       
workers=2
pidfile=/opt/proj/script/uwsgi.pid       
http=:8080
static-map=/static=/opt/proj/ApiAutomation/static
uid=root
gid=root
master=true
vacuum=true
thunder-lock=true
enable-threads=true
harakiri=30
post-buffering=4096
daemonize=/opt/proj/script/uwsgi.log

运行uwsgi --ini uwsgi.ini可以运行项目,出错看uwsgi.log,如果成功出现uwsgi.sock文件

 

nginx安装

在cd /etc/nginx/conf.d/里面创建api.conf文件

内容为:

server {           # 这个server标识我要配置了
        listen 80; # 我要监听那个端口
        server_name 192.168.132.128 ; # 你访问的路径前面的url名称
        access_log /var/log/nginx/access.log main; # Nginx日志配置
        charset utf-8; # Nginx编码
        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; # 支持压缩的类型

        error_page 404 /404.html; # 错误页面
        error_page 500 502 503 504 /50x.html; # 错误页面

    # 指定项目路径uwsgi
        location / { # 这个location就和咱们Django的url(r'^admin/', admin.site.urls),
                include uwsgi_params; # 导入一个Nginx模块他是用来和uWSGI进行通讯的
                uwsgi_connect_timeout 30; # 设置连接uWSGI超时时间
                uwsgi_pass unix:/opt/proj/script/uwsgi.sock; # 指定uwsgi的sock文件所有动态请求就会直接丢给他               
        }

    # 指定静态文件路径
        location /static/ {
                alias /opt/proj/ApiAutomation/static/;
                
        }

}

运行nginx -s reload就可以

 

posted @ 2018-11-15 11:22  oneforall97  阅读(39)  评论(0)    收藏  举报