HttpRunner nginx+uwsgi 部署 HttpRunnerManager

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

首先感谢大佬做的平台 @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 #3 · 2018年05月22日 Author

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

Jacc #2 · 2018年05月19日 Author

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

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