阿里云ubuntu16.04上搭建gunicorn+supervisor+nginx详解
2016-11-25 11:11
549 查看
ubuntu上搭建gunicorn+supervisor+nginx
① pip安装gunicornpip install gunicorn
关于gunicorn的启动命令是:
gunicorn -w 4 -b 0.0.0.0:7000 myapp: app
② pip 安装supervisor
sudo pip install supervisor
注意:需要在安装在sudo下
配置方式:
echo_ supervisord_conf > supervisor.conf vim supervisor.conf
接下来需要在conf最后添加自己的app项目
[program: myapp] command=/你的venv路径/gunicorn -w4 -b 0.0.0.0:7000 manage:app directory=/home/ubuntu/tdz/flask-projects-manage startsecs=0 stopwaitsecs=0 autostart=false autorestart=false stdout_logfile=/home/ubuntu/tdz/flask-projects-manage/log/gunicorn.log stderr_logfile=/home/ubuntu/tdz/flask-projects-manage/log/gunicorn.err
最好把管理界面打开,即直接用http可视化管理,省的输命令:
[inet_http_server] ; inet (TCP) server disabled by default port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface) username=user ; (default is no username (open server)) password=123 ; (default is no password (open server))
还有这个:
[supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket serverurl=http://0.0.0.0:9001 ; use an http:// url to specify an inet socket username=user ; should be same as http_username if set password=123 ; should be same as http_password if set ;prompt=mysupervisor ; cmd line prompt (default "supervisor") ;history_file=~/.sc_history ; use readline history if available
ps:上面两个取消注释就好,改一下自己的用户名密码即可,这个用户名是用来登录可视化管理的
③ 安装nginx
sudo apt-get install nginx
然后配置文件/etc/nginx/nginx.conf,主要是将你所要的服务server给include进去,例如
include /etc/nginx/sites-enabled/nginx_gunicorn.conf; include /etc/nginx/sites-enabled/nginx_django_gunicorn.conf;
因为我有两个服务需要监听
其中一个conf内容是:
server{ listen 0.0.0.0:8080; location /static/ { include /etc/nginx/mime.types; # Example: # root /full/path/to/application/static/file/dir; root /home/ubuntu/tdz/flask-projects-manage/app/; } location = /favicon.ico { root /home/ubuntu/tdz/flask-projects-manage/app/static/f.ico; } location / { proxy_pass http://127.0.0.1:7000; proxy_redirect off; proxy_set_header Host $host:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
最后记得在supervisor.conf下加上nginx项目
[program:nginx] command=/usr/sbin/nginx startsecs=0 stopwaitsecs=0 autostart=false autorestart=false stdout_logfile=/home/ubuntu/tdz/flask-projects-manage/log/nginx.log stderr_logfile=/home/ubuntu/tdz/flask-projects-manage/log/nginx.err
好了,部署完了,进入9001端口启动即可。
“`
相关文章推荐
- 从0开始搭建阿里云(腾讯云)ubuntu16.04 nodejs + nginx + mysql + pm2 服务(三、搭建mysql环境)
- 阿里云Ubuntu16.04搭建LAMP+私有云nextcloud
- 从0开始搭建阿里云(腾讯云)ubuntu16.04 nodejs + nginx + mysql + pm2 服务(四、pm2环境搭建)
- 阿里云服务器ECS Ubuntu16.04-64-bit学习之二:搭建apache2外网能访问的web网站
- 阿里云搭建基于MatlabMPI的集群(三):Ubuntu16.04安装MATLAB2014a
- 阿里云学生服务器搭建网站(2)-Ubuntu16.04安装php开发环境
- 阿里云 ubuntu16.04上如何搭建IPSec服务
- 从0开始搭建阿里云(腾讯云)ubuntu16.04 nodejs + nginx + mysql + pm2 服务(一、搭建nopdejs环境)
- 从0开始搭建阿里云(腾讯云)ubuntu16.04 nodejs + nginx + mysql + pm2 服务(五、nginx https 配置)
- 阿里云搭建基于MatlabMPI的集群(二):Ubuntu16.04基于VNC的图形界面安装
- ubuntu 16.04 lamp的搭建
- ubuntu16.04搭建Hadoop2.7.2+spark1.6.1+mysql+hive2.0.0伪分布学习环境
- 阿里云Ubuntu环境搭建Docker服务
- Ubuntu16.04 jdk+Eclipse环境搭建, jdk版本自由切换
- django 阿里云上 ubuntu-x64 python+django+mysql 开发环境搭建
- ubuntu 16.04 搭建lamp的苦逼经历
- 基于阿里云 Ubuntu 的 LAMP 网站搭建及配置完全教程
- 【阿里云服务器】【ubuntu14.04】搭建apache+php+mysql+phalcon
- Ubuntu16.04搭建ionic开发环境
- 阿里云Ubuntu系统+Apache2+PHP搭建gitblog