rails应用的部署
简单部署
RAILS_ENV=production rake secret /etc/profile
export SECRET_KEY_BASE=刚才生成的密钥
source /etc/profile
这种简单的把端口暴露出去, 可能出现服务得不到应答的问题,tcp被各种close_wait阻塞。解决的办法:架设nginx。
rails 的web服务主要有puma, unicorn, passenger
Puma设置
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
environment ENV.fetch("RAILS_ENV") { "prodution" }
daemonize trueworkers 2
application_path = "/home/apphome"
worker_timeout 60
stdout_redirect "#{application_path}/shared/log/puma.stdout.log"
state_path "#{application_path}/shared/tmp/sockets/puma.state"
pidfile "#{application_path}/shared/tmp/pids/puma.pid"
bind "unix://#{application_path}/shared/sockets/app.sock"
activate_control_app "unix://#{application_path}/shared/sockets/pumactl.sock"
# directory "#{application_path}/current"
preload_app!
rails s -e production 就可以启动了
# 通过ps -aux| grep 查看一下是否启动,如果没有启动成功,把daemonzie注释掉,就能看到报错信息。
Nginx配置
/etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; include /etc/nginx/mime.types;
default_type application/octet-stream; include /etc/nginx/conf.d/*.conf;
upstream app {
server unix://home/上面puma文件中填的bind路径.sock; } server {
listen 4000 default_server;
server_name 0.0.0.0; # 服务器名
root app的根目录; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
proxy_redirect off;
proxy_pass http://app; # 这里填写upstream的名称
}
keepalive_timeout 10; error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
重启nginx: nginx -t; nginx -s reload
rails应用的部署的更多相关文章
- PassengerNginxdebian快速部署Rails
Passenger/Nginx/Debian快速部署Rails PassengerNginxdebian快速部署Rails 安装所需的linux包 sudo apt-get install ...
- 使用 Capistrano 和写作 Ruby 迭代边缘部署
想边自己写ruby代码,边部署随时能够到处查看,heroku域名又不友好,速度在国内又慢.于是乎想起来capistrano,于是学起 ... capistrano 一点入门认知 https://www ...
- rails5 后台入门(api mode)
1. Installation (Centos为例) 1.1安装rvm (http://rvm.io/) gpg2 --recv-keys 409B6B1796C275462A1703113804BB ...
- apache服务器安装以及使用passenger插件部署rails应用
小例子可以部署在rails自带的WEBrick上,逐渐往后走还得上Apache. 安装apache服务器 命令是sudo apt-get install apache2 安装passenger插件 安 ...
- rails创建项目,部署,测试流程(rails5.0+ruby2.3.1)
rails new test_app --skip-test-unit 不生成默认的test,稍后用rspeccd test_app 修改Gemfile(大部分为自动生成) source 'https ...
- Ruby on Rails Tutorial 第一章 之 Heroku部署
1.目的:用Heroku将开发环境部署到生产环境中.Heroku专门用于部署Rails和其他Web应用,部署Rails应用的过程非常简单——只要源码纳入Git版本控制系统就好. 2.搭建Heroku部 ...
- Passenger/Nginx/Debian快速部署Rails
安装所需的linux包 sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl gi ...
- Rails在MacOS上搭建Heroku部署环境
heroku只是用postgresql,而不能兼容sqlite数据库.所以很重要的一步就是在部署实际产品的时候将数据库类型修改为postgresql,否则你将无法push到heroku上去. hero ...
- Ubuntu 云服务器上部署自己的 Rails 应用
自学rails一段时间了,之前只用heroku部署了网站,想尝试把网站以一个更“正经”的方式呈现出来,就买了一个阿里云服务器.参考了网上部分rails部署教程,过程中也遇到了一些问题,所以在完成之后总 ...
随机推荐
- 云笔记项目-Spring事务学习-传播SUPPORTS
接下来测试事务传播属性SUPPORTS Service层 Service层将方法的事务传播属性设置为SUPPORTS LayerT层代码 package LayerT; import javax.an ...
- aop原理及理解
概念 Aspect Oriented Programming,面向切面编程,实际上它是一个规范.一种设计思路,总之是抽象的. 先上图 使用目的 从项目结构上来说 对业务逻辑的各个部分进行隔离,降低业务 ...
- Java相关查询记录
Version of Spring Facet could not be detected. http://yijiesuifeng.iteye.com/blog/2221444
- vue在main.js中全局引用css的方法及坑
步骤: 1.配置文件webpack.config.js: { test:/\.css$/, loader:'style-loader!css-loader' } 坑1:-loader尾缀 坑2:Mod ...
- 138 条 Vim 命令、操作、快捷键全集
命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...
- systemd 编写服务管理脚本---学习
转载:https://www.cnblogs.com/sparkdev/p/8521812.html 我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web serve ...
- linux下查看动态链接库so文件的依赖的相关组建
我们很多c程序在windows下是以dll形式展现的,在linux则是以so 形式展现的. windows一般不会因为编译dll文件的编译器版本不同而出先dll文件不能执行. 但是linux下,不同版 ...
- pycharm工具配置
灰色主题 菜单栏File --> Settins --> Appearance & Behavior --> Appearance, Theme改成Darcula,然后App ...
- Odoo domain 中的 like, ilike, =like, =ilike
Odoo domain 中的 like, ilike, =like, =ilike 举例说明[转] Odoo domain 中的 like, ilike, =like, =ilike Odoo d ...
- Linux-Slabinfo
1.内存管理有两个算法:伙伴算法(buddy system)和slab算法.伙伴算法是以页为单位管理内存,slab算法是以字节为单位管理内存,是内核的小内存管理算法.特点是基于对象进行管理. slab ...