zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    HTTP协议
    优化特定类型的查询
    Feign性能优化注意事项
    Spring Cloud(Netflix) Feign: 以Dubbo暴露服务的方式使用Feign
    Swagger注解
    Myeclipse、eclipse安装lombok
    微服务和单体架构的区别以及springClould版本的说明
    索引优化是对查询性能优化最有效的手段
    Schemal和数据类型的优化
    spring定时器的使用
  • 原文地址:https://www.cnblogs.com/yxi-liu/p/10331310.html
Copyright © 2011-2022 走看看