HttpRunner nginx+uwsgi 部署 HttpRunnerManager

Jacc · 2018年05月18日 · 最后由 Jacc 回复于 2018年05月22日 · 939 次阅读

首先感谢大佬做的平台 @debugtalk @yinquanwang 地址:https://github.com/HttpRunner/HttpRunnerManager
下面开始我们的步骤:

0、前置

git clone项目后,参考readme,保证项目可以调试运行
在settings.py 中,#29改为False;放掉注释行#123 “STATIC_ROOT............”;注释掉#130-132;
收集静态文件python manage.py collectstatic

1、安装nginx和uwsgi

nginx

sudo apt-get install nginx(我的系统是Ubuntu/Debian)

uwsgi

pip install uwsgi

2、配置nginx.conf和uwsgi

nginx配置
cd /etc/nginx/sites-available
sudo vim httprunner_nginx.conf
cd ../sites-enabled
sudo rm default
sudo ln -s ../sites-available/httprunner_nginx.conf httprunner

httprunner_nginx.conf
# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/chen/PycharmProjects/HttpRunnerManager/HttpRunnerManager.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name example.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /static {
        alias /home/chen/PycharmProjects/HttpRunnerManager/static; # 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
    }
}

uwsgi配置

项目目录有默认的uwsgi.ini文件,更改为自己配置即可,我的如下

uwsgi.ini
# myweb_uwsgi.ini file
[uwsgi]

# Django-related settings

project = HttpRunnerManager
base = /home/chen/PycharmProjects

chdir = %(base)/%(project)
module = %(project).wsgi


master = true
processes = 4


socket = %(base)/%(project)/%(project).sock
chmod-socket = 666
vacuum = true

3、启动nginx和uwsgi

重启nginx

sudo /etc/init.d/nginx restart

启动uwsgi

uwsgi --ini /home/chen/PycharmProjects/HttpRunnerManager/uwsgi.ini

4、开启worker,参考readme

5、请求http://127.0.0.1/api/login/

参考文档 http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

共收到 3 条回复 时间 点赞
Jacc #2 · 2018年05月19日 作者

增加docker配置https://github.com/chenchengyuan/HttpRunnerManager-docker.git
项目对应HttpRunnerManager项目的docker配置,只含基本功能的docker配置,不涉及worker等;

Jacc #3 · 2018年05月22日 作者

今天在centos上配置,始终不能访问,后来发现日志里,有连不上uwsgi的报错,最终靠setenforce 0关闭 SELinux解决

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册