美文网首页
nginx+passenger配置rails的生产环境

nginx+passenger配置rails的生产环境

作者: G_wei | 来源:发表于2019-03-15 00:31 被阅读0次
    1. 先编译方式安装好nginx ==> 安装教程
    2. 安装passenger
    macdeMac-mini:src g_wei$ gem install passenger
    macdeMac-mini:src g_wei$ gem list | grep passenger
    passenger (6.0.0)
    # gem安装后的路径
    macdeMac-mini:nginx_module g_wei$ pwd
    /Users/g_wei/.rvm/gems/ruby-2.4.4/gems/passenger-6.0.0/src/nginx_module
    
    1. 编译安装,只需要在原来的编译配置参数后补上就行
    # 到nginx的包目录下
    # 原来nginx的配置
    macdeMac-mini:nginx-1.14.2 g_wei$ su
    Password:
    sh-3.2# nginx -V
    nginx version: nginx/1.14.2
    built by clang 10.0.0 (clang-1000.10.44.4)
    built with OpenSSL 1.0.2p  14 Aug 2018
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/bin/nginx --with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl/include' --with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-ipv6 --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
    
    # 重新编译安装nginx,注意最后的 --add module 语句
    sh-3.2# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/bin/nginx --with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl/include' --with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-ipv6 --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/Users/g_wei/.rvm/gems/ruby-2.4.4/gems/passenger-6.0.0/src/nginx_module
    sh-3.2# make install
    # 如果没有跑错,不出意外,passenger已成功安装
    
    1. 看到这个就代表安装成功了


      image.png
    2. 配置项目的nginx文件
      在编译完成后,修改Nginix的配置文件(/opt/nginx/conf/nginx.conf),在HTTP模块内添加如下一行后,重启Nginix即可

      image.png
    3. 项目的配置文件示例

    server {
          listen       80;
          server_name  local.society.com;
    
          #charset koi8-r;
    
          #access_log  logs/host.access.log  main;
    
          root /data/web/ruby/society/public/;
          passenger_enabled on;
          # rails_env development;
          rails_env production;
          passenger_ruby /Users/g_wei/.rvm/gems/ruby-2.4.4/wrappers/ruby;
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   html;
          }
      }
    
    1. passenger常用命令
    passenger-config help # 查看相关命令
    # 重启项目
    sh-3.2# passenger-config restart-app
    Please select the application to restart.
    Tip: re-run this command with --help to learn how to automate it.
    If the menu doesn't display correctly, press '!'
    
     ‣   /data/web/ruby/redmine-4.0.0 (production)
         /data/web/ruby/soc
    
    # 查看passenger状态
    sh-3.2# passenger-status
    Version : 6.0.0
    Date    : 2019-03-15 00:30:18 +0800
    Instance: bhNDzEYm (nginx/1.14.2 Phusion_Passenger/6.0.0)
    
    ----------- General information -----------
    Max pool size : 6
    App groups    : 2
    Processes     : 1
    Requests in top-level queue : 0
    
    ----------- Application groups -----------
    /data/web/ruby/redmine-4.0.0 (production):
      App root: /data/web/ruby/redmine-4.0.0
      Requests in queue: 0
    
    /data/web/ruby/society (production):
      App root: /data/web/ruby/society
      Requests in queue: 0
      * PID: 12451   Sessions: 0       Processed: 4       Uptime: 11m 8s
        CPU: 0%      Memory  : 33M     Last used: 7m 34s ago
    
    

    相关文章

      网友评论

          本文标题:nginx+passenger配置rails的生产环境

          本文链接:https://www.haomeiwen.com/subject/voghmqtx.html