使用Unicorn将Sinatra应用部署到Nginx
2015-05-29 13:28
751 查看
将Sinatra应用写好了之后,可以使用unicorn将之部署到Nginx上,Sinatra的应用可以参考我的boilerplate:https://github.com/frederichchen/fc_sinatra_boilerplate
Sinatra平时开发的时候我用Thin来做服务器,部署的时候则使用unicorn,因此需要首先: gem install unicorn
部署的时候需要先进入Sinatra应用的根目录,在其中分别建立 tmp、tmp/sockets、tmp/pids和log 四个目录。
然后在Sinatra应用的根目录中新建一个unicorn.rb文件,内容为:
接下来配置Nginx,编辑其配置文件 nginx.conf ,在http部分加入如下如下:
启动服务的时候先运行:unicorn -c path/to/unicorn.rb -E development -D
其中-E指定环境为development,-D表示以daemon运行。
然后启动nginx服务,访问 http://localhost/ 就可以了。
要停止服务,则运行 cat /path/to/app/tmp/pids/unicorn.pid | xargs kill -QUIT
如果unicorn没有能够清理干净,则还需要执行以下两个命令:
rm /path/to/app/tmp/sockets/unicorn.socket
rm /path/to/app/tmp/pids/unicorn.pid
以上操作参考 https://github.com/sinatra/sinatra-recipes/blob/master/deployment/nginx_proxied_to_unicorn.md 。
Sinatra平时开发的时候我用Thin来做服务器,部署的时候则使用unicorn,因此需要首先: gem install unicorn
部署的时候需要先进入Sinatra应用的根目录,在其中分别建立 tmp、tmp/sockets、tmp/pids和log 四个目录。
然后在Sinatra应用的根目录中新建一个unicorn.rb文件,内容为:
@dir = "/path/to/app/" worker_processes 2 working_directory @dir timeout 60 listen "#{@dir}tmp/sockets/unicorn.sock", :backlog => 64 pid "#{@dir}tmp/pids/unicorn.pid" stderr_path "#{@dir}log/unicorn.stderr.log" stdout_path "#{@dir}log/unicorn.stdout.log"
接下来配置Nginx,编辑其配置文件 nginx.conf ,在http部分加入如下如下:
http { ... upstream unicorn_server { server unix:/path/to/app/tmp/sockets/unicorn.sock fail_timeout=0; } server { listen 80; server_name localhost; root /path/to/app/public; location / { try_files $uri @app; } location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; # pass to the upstream unicorn server mentioned above proxy_pass http://unicorn_server; } } }
启动服务的时候先运行:unicorn -c path/to/unicorn.rb -E development -D
其中-E指定环境为development,-D表示以daemon运行。
然后启动nginx服务,访问 http://localhost/ 就可以了。
要停止服务,则运行 cat /path/to/app/tmp/pids/unicorn.pid | xargs kill -QUIT
如果unicorn没有能够清理干净,则还需要执行以下两个命令:
rm /path/to/app/tmp/sockets/unicorn.socket
rm /path/to/app/tmp/pids/unicorn.pid
以上操作参考 https://github.com/sinatra/sinatra-recipes/blob/master/deployment/nginx_proxied_to_unicorn.md 。
相关文章推荐
- 让服务器apache/iis/nginx支持.apk/ipa文件下载
- Ubuntu下Nginx的安装和简单配置
- demopu告诉你nginx+php 出现404错误解决方法
- 使用nginx进行负载均衡
- demopu告诉你nginx+php 出现404错误解决方法
- ab测试nginx的性能
- Nginx禁止通过IP,未绑定域名访问服务器
- wordpress在Linux nginx下权限设置
- ecshop在nginx下实现负载均衡
- nginx如何实现404状态返回 200隐藏URL
- 分布式文件系统(FastDFS+Tengine+fastdfs-nginx-module)
- keepalived+nginx高可用配置
- nginx缓存命中率统计(转)
- nginx常用命令
- nginx主备配置
- Nginx的常用命令。
- nginx服务器access_log日志分析及配置详解
- Nginx学习总结(1):Nginx简介
- Linux下nginx安装与配置
- Linux下nginx安装与配置