为Rails应用配置apache

时间:2018-07-18 13:58:05

标签: ruby-on-rails apache

我有一个RoR应用程序,该应用程序通过capistrano部署到服务器上。在此服务器中,我已经安装了Apache,并在其中为此应用程序激活了一个站点。

<VirtualHost *:80>
  ServerName kiui.clever-test.com

  RewriteEngine On

  DocumentRoot /home/deploy/kiui/current/public

  <Directory "/home/deploy/kiui/current/public">
    Options FollowSymLinks
    AllowOverride None
    #Order allow,deny
    #Allow from all
    Require all granted
    #gzip stuff
    SetEnv no-gzip

    # RewriteEngine on
    # Make sure the browser supports gzip encoding before we send it
    #RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
    #RewriteCond %{REQUEST_FILENAME}.gz -s
    #RewriteRule ^(.+) $1.gz [L]
  </Directory>
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]

  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://kiui_cluster%{REQUEST_URI} [P,QSA,L]

  ErrorLog /home/deploy/kiui/shared/log/apache.log
  CustomLog /home/deploy/kiui/shared/log/apache.log combined
</VirtualHost>

在/etc/apache2/conf-enabled/cluster.conf中,我创建集群以在端口12050中运行该应用程序,因为在该服务器中将有多个应用程序。

<Proxy balancer://kiui_cluster/>
  BalancerMember http://0.0.0.0:12050 retry=0
</Proxy>

我的puma配置如下:

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

port        ENV.fetch("PORT") { 12050 }

environment ENV.fetch("RAILS_ENV") { "production" }

workers ENV.fetch("WEB_CONCURRENCY") { 2 }

pidfile '/home/deploy/kiui/shared/tmp/pids/puma.pid'

state_path '/home/deploy/kiui/shared/tmp/pids/puma.state'

stdout_redirect '/home/deploy/kiui/shared/log/puma_access.log', '/home/deploy/kiui/shared/log/puma_error.log', true

prune_bundler

plugin :tmp_restart

数据库连接良好,因为所有迁移均已成功完成。子域kiui.clever-test.com的DNS A记录指向服务器的IP。

问题是,当我使用cap production deploy进行部署时,运行良好,但是当我转到kiui.clever-test.com时,出现503错误。 apache.log中的错误:

[Wed Jul 18 13:55:16.015721 2018] [proxy:error] [pid 12628:tid 139680012019456] (111)Connection refused: AH00957: HTTP: attempt to connect to 0.0.0.0:12050 (0.0.0.0) failed
[Wed Jul 18 13:55:16.015782 2018] [proxy:error] [pid 12628:tid 139680012019456] AH00959: ap_proxy_connect_backend disabling worker for (0.0.0.0) for 0s
[Wed Jul 18 13:55:16.015793 2018] [proxy_http:error] [pid 12628:tid 139680012019456] [client 83.39.108.216:50558] AH01114: HTTP: failed to make connection to backend: 0.0.0.0
83.39.108.216 - - [18/Jul/2018:13:55:16 +0000] "GET / HTTP/1.1" 503 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
83.39.108.216 - - [18/Jul/2018:13:55:16 +0000] "GET /favicon.ico HTTP/1.1" 200 296 "http://kiui.clever-test.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"

0 个答案:

没有答案