rails - homeland 论坛的部署过程和注意事项

访问量: 198

refer to: https://github.com/ruby-china/homeland

部署过程非常简单,安装好对应的依赖,环境,git clone code 即可。

修改 HomeController , 那里的404 要注释掉

  3 class HomeController < ApplicationController
  4   def uploads
  5 #    return render_404 if Rails.env.production?

ENV中要有 domain

[env]
  PORT = "8080"
  SERVER_COMMAND = "bundle exec puma -C config/puma.rb"
  DATABASE_URL = "postgres://postgres:db190dffa0a8bfd30fe78a1802fe154b3868a4f64xxx@xxx.internal:5432/xxx-com-db"
  REDIS_URL = "redis://default:xxxxxal:6379"
  domain = 'xxxi.com'

安装 imagemagick 修改 Dockerfile

ARG PROD_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0 imagemagick"
ENV PROD_PACKAGES=${PROD_PACKAGES}

用户上传的头像位置(public/files )要保存

fly volumes create files --size 1 

然后修改fly.toml

[mounts]
  destination = "/app/public/uploads"
  source = "files"

对于user, 设置它的state = admin ( 99 ) 就是管理员了

irb(main):005:0> User.states
=> {"deleted"=>-1, "member"=>1, "blocked"=>2, "vip"=>3, "hr"=>4, "maintainer"=>90, "admin"=>99}

对于手动的Nginx 部署需要注意:

1. nginx 的站点配置看起来如下.

 server {
      listen 80;
      return 301 https://$host$request_uri;
      server_name forum.yangqigong.cn;
  }

  server {
      listen 443 ssl;
      server_name forum.yangqigong.cn;

      ssl_certificate   /opt/ssl/8311517_forum.yangqigong.cn.pem;
      ssl_certificate_key  /opt/ssl/8311517_forum.yangqigong.cn.key;
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_prefer_server_ciphers on;

      location / {
          proxy_pass          http://forum_yangqigong_cn_servers;
          proxy_redirect      default;
          proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header    X-Real-IP $remote_addr;
          proxy_set_header    Host $http_host;
          proxy_next_upstream http_502 http_504 error timeout invalid_header;
          proxy_set_header    X-Forwarded-Proto https;    # 这里最最重要 
      }
      location ~ ^/assets|packs|system/ {
        root /opt/app/homeland/public;
        expires 1y;
        add_header Cache-Control public;
        add_header ETag "";
        break;
      }

  }

  upstream forum_yangqigong_cn_servers{
         server localhost:3000;
  }

2. 设置  config/environments/production.rb     

config.force_ssl = true

3. 回复日志 ,修改文件同上

+  #给他隐藏掉
+  #if ENV["RAILS_LOG_TO_STDOUT"].present?
+  #  logger = ActiveSupport::Logger.new($stdout)
+  #  logger.formatter = config.log_formatter
+  #  config.logger = ActiveSupport::TaggedLogging.new(logger)
+  #end

4. 设置 静态asset 路径

      location ~ ^/assets|packs|system/ {
        root /opt/app/homeland/public;
        expires 1y;
        add_header Cache-Control public;
        add_header ETag "";
        break;
      }

5. 要启动sidekiq

homeland 没有使用activejob, 而是sidekiq, 所以这就要求, 需要额外的启动脚本来运行它。

bundle exec sidekiq -e production

订阅/RSS Feed

Subscribe