您的位置:首页 > 运维架构 > Nginx

beego项目部署--使用supervisor和nginx

2017-03-20 00:00 477 查看
用一段时间基于beego开发了一个admin系统,等到部署的时候遇到了一堆问题,用了整整一天才处理好,现在整理下来,分享给大家,希望对大家有所帮助吧。
系统环境:centos 7.2 python:2.7.5

nginx安装

建议直接使用 yum install nginx安装,其他方式安装遇到了很多问题,所以推荐使用这个方式安装。然后编辑nginx 的配置文件:
vim /etc/nginx/nginx.conf 文件,添加如下代码:

include /etc/nginx/conf.d/*.conf;

然后在/etc/nginx/conf.d/目录下创建beepkg.conf文件,添加如下代码:

server {
listen       80;
server_name  .b.com;     #项目解析的域名

charset utf-8;
access_log  /home/b.com.access.log  main;   #输出的日志的位置

location /(css|js|fonts|img)/ {
access_log off;
expires 1d;

root "/path/to/app_b/static";                  #项目静态资源的位置
try_files $uri @backend;
}

location / {
try_files /_not_exists_ @backend;
}

location @backend {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host            $http_host;

proxy_pass http://127.0.0.1:8081;    #这里的端口号要和项目conf/app.conf里面指定的端口号一致
}
}


supervisor安装

同样,推荐使用 yum -y install supervisor安装,使用源码安装或者easy_install安装,使用systemctl restart supervisord 会报错,提示没有对应的目录。通过这种方式安装后,会在/etc/下自动创建 supervisord.conf文件和supervisord.d目录。修改supervisord.conf文件,添加如下代码

[include]
files = /etc/supervisord.d/*.conf

然后在 /etc/supervisord.d/目录下创建项目的配置文件 vim beepkg.conf,添加如下代码:

[program:beepkg]
directory = /opt/app/beepkg       #项目文件夹
command = /opt/app/beepkg/beepkg   #项目可执行文件位置
autostart = true
startsecs = 5
user = root
redirect_stderr = true
stdout_logfile = /var/log/supervisord/beepkg.log       #输出日志文件的位置

首次启动 supervisord,然后使用supervisorctl start beepkg,如果没有问题,使用systemctl restart supervisord,
再使用systemclt restart nginx,先后顺序不能颠倒
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx supervisord