简单部署

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应用的部署的更多相关文章

  1. PassengerNginxdebian快速部署Rails

    Passenger/Nginx/Debian快速部署Rails   PassengerNginxdebian快速部署Rails     安装所需的linux包 sudo apt-get install ...

  2. 使用 Capistrano 和写作 Ruby 迭代边缘部署

    想边自己写ruby代码,边部署随时能够到处查看,heroku域名又不友好,速度在国内又慢.于是乎想起来capistrano,于是学起 ... capistrano 一点入门认知 https://www ...

  3. rails5 后台入门(api mode)

    1. Installation (Centos为例) 1.1安装rvm (http://rvm.io/) gpg2 --recv-keys 409B6B1796C275462A1703113804BB ...

  4. apache服务器安装以及使用passenger插件部署rails应用

    小例子可以部署在rails自带的WEBrick上,逐渐往后走还得上Apache. 安装apache服务器 命令是sudo apt-get install apache2 安装passenger插件 安 ...

  5. rails创建项目,部署,测试流程(rails5.0+ruby2.3.1)

    rails new test_app --skip-test-unit 不生成默认的test,稍后用rspeccd test_app 修改Gemfile(大部分为自动生成) source 'https ...

  6. Ruby on Rails Tutorial 第一章 之 Heroku部署

    1.目的:用Heroku将开发环境部署到生产环境中.Heroku专门用于部署Rails和其他Web应用,部署Rails应用的过程非常简单——只要源码纳入Git版本控制系统就好. 2.搭建Heroku部 ...

  7. Passenger/Nginx/Debian快速部署Rails

    安装所需的linux包 sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl gi ...

  8. Rails在MacOS上搭建Heroku部署环境

    heroku只是用postgresql,而不能兼容sqlite数据库.所以很重要的一步就是在部署实际产品的时候将数据库类型修改为postgresql,否则你将无法push到heroku上去. hero ...

  9. Ubuntu 云服务器上部署自己的 Rails 应用

    自学rails一段时间了,之前只用heroku部署了网站,想尝试把网站以一个更“正经”的方式呈现出来,就买了一个阿里云服务器.参考了网上部分rails部署教程,过程中也遇到了一些问题,所以在完成之后总 ...

随机推荐

  1. js判断一个变量是数组还是对象

    判断变量是数组还是对象,使用Object.prototype.toString.call(),兼容性好,切勿使用typeof来判断对象或者数组,因为typeof得到的都是object: functio ...

  2. hdu4622(hash解法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 Now you are back,and have a task to do:Given you ...

  3. strin 数组转换成int 数组

    string[] strarry = ids.Trim(',').Split(','); int[] arryInts = Array.ConvertAll<string, int>(st ...

  4. 十七、Java中数组常见的几种排序方法!

    转载自:https://www.cnblogs.com/bekeyuan123/p/6891875.html 数组的定义: // 3种定义方式 int[] arr = new int[5]; int[ ...

  5. Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again

    虚拟机恢复快照后,使用yum安装软件,提示下面的信息,开始以为是yum源的问题或者DNS的问题,但是无果,最后再看一下服务器的时间,坑了,还原快照,时间变成以前的了. [root@localhost ...

  6. Node.js server-side javascript cpu占用高

    也不知道微软咋想的,不搞死我们的电脑不罢休 https://developercommunity.visualstudio.com/content/problem/27033/nodejs-serve ...

  7. 使用nginx反向代理实现隐藏端口号

    使用nginx反向代理实现隐藏端口号 在服务器上下载安装nginx,主要是修改配置nginx.conf. 用proxy_pass里面配置要转发的域名+端口,相当于这一部分是被域名替换的部分,在http ...

  8. redis相关运维命令

    1. 查询redis里面的大key? 在redis实例上执行bgsave,然后我们对dump出来的rdb文件进行分析,找到其中的大KEY 有个不太推荐的命令,debug object xxx 可以看到 ...

  9. 在Java的Condition接口【唤醒全部线程】

    在Java的Condition接口中,存在的几个方法跟Synchronized中的wait(),waitall(),wait(time ^),这个几个方法一一对应起来,但是在Lock.newCondi ...

  10. NOVO SOP (SOP简介及历史)

    SOP(Standard Operation Procedure),标准作业程序. 一.什么是SOP(标准作业程序) 所谓SOP,是 Standard Operation Procedure三个单词中 ...