首先感谢大佬做的平台 @debugtalk @yinquanwang 地址:https://github.com/HttpRunner/HttpRunnerManager;
下面开始我们的步骤:
git clone 项目后,参考 readme,保证项目可以调试运行
在 settings.py 中,#29 改为 False;放掉注释行 #123 “STATIC_ROOT............”;注释掉 #130-132;
收集静态文件python manage.py collectstatic
sudo apt-get install nginx
(我的系统是 Ubuntu/Debian)
pip install uwsgi
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
# 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.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
sudo /etc/init.d/nginx restart
uwsgi --ini /home/chen/PycharmProjects/HttpRunnerManager/uwsgi.ini
参考文档 http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html