Rails 4启用force_ssl原因301 |阿帕奇乘客

时间:2020-07-28 03:53:27

标签: apache ruby-on-rails-4 passenger tls1.2 ubuntu-20.04

我有一个Rails应用程序(Rails 4.2.4 + Apache 2.4.43 + Passenger 5.0.16)。 rails应用程序是其余的Api应用程序。我对Rails和Apache配置比较陌生。

打开config.force_ssl = true时,检查apache访问日志时总是得到301。当config.force_ssl = false时,应用程序正常工作。该应用程序以前在Ubuntu 15.04上,我正尝试升级到Ubuntu 20.04。并不是说15.04,没有问题。任何帮助或指示将不胜感激。谢谢。

以下是apache配置。 (我正在尝试访问alt.myapp.com上的站点-不是真实的URL)。我尝试使用TLS来使用SSLProtocol协议,但无济于事。

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName cloud.myapp.com
    ServerAlias alt.myapp.com developer.myapp.com localhost

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/sites/cloud.myapp.com/current/public
    
    AllowEncodedSlashes NoDecode

    # Available levels: crit (0), error (1), warn (2), notice (3), info (4), debug (5), debug2 (6), debug3 (7)
    PassengerLogLevel 4
    PassengerRuby /usr/local/rvm/wrappers/default/ruby
    PassengerAppEnv vapor

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    <Directory "/var/www/sites/cloud.myapp.com/current/public">
        Options FollowSymLinks
        Require all granted
    </Directory>

</VirtualHost>

<VirtualHost *:443>
    ServerName cloud.myapp.com
    ServerAlias alt.myapp.com localhost

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/sites/cloud.myapp.com/current/public
    
    AllowEncodedSlashes NoDecode

    # Available levels: crit (0), error (1), warn (2), notice (3), info (4), debug (5), debug2 (6), debug3 (7)
    PassengerLogLevel 4
    PassengerRuby /usr/local/rvm/wrappers/default/ruby
    PassengerAppEnv vapor

    ErrorLog ${APACHE_LOG_DIR}/error_ssl.log
    CustomLog ${APACHE_LOG_DIR}/access_ssl.log combined

    # SSL details
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

    # Private key
    SSLCertificateFile      /var/www/sites/cloud.myapp.com/current/config/keys/myapp.com.crt
    SSLCertificateKeyFile   /var/www/sites/cloud.myapp.com/current/config/keys/myapp.com.private_key.pem
    SSLCertificateChainFile /var/www/sites/cloud.myapp.com/current/config/keys/gd_bundle-g2-g1.crt

    RequestHeader set X_FORWARDED_PROTO 'https'

    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://localhost/
    ProxyPassReverse / http://localhost/

</VirtualHost>

<VirtualHost *:3000>
    ServerName cloud.myapp.com
    ServerAlias developer.myapp.com alt.myapp.com localhost

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/sites/cloud.myapp.com/current/public

    # Available levels: crit (0), error (1), warn (2), notice (3), info (4), debug (5), debug2 (6), debug3 (7)
    PassengerLogLevel 4
    PassengerRuby /usr/local/rvm/wrappers/default/ruby
    PassengerAppEnv vapor

    ErrorLog ${APACHE_LOG_DIR}/error_developer.log
    CustomLog ${APACHE_LOG_DIR}/access_developer.log combined

    # SSL details
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

    # Private key
    SSLCertificateFile      /var/www/sites/cloud.myapp.com/current/config/keys/myapp.com.crt
    SSLCertificateKeyFile   /var/www/sites/cloud.myapp.com/current/config/keys/myapp.com.private_key.pem
    SSLCertificateChainFile /var/www/sites/cloud.myapp.com/current/config/keys/gd_bundle-g2-g1.crt

    RequestHeader set X_FORWARDED_PROTO 'https'

    ProxyRequests Off
    ProxyPreserveHost Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://localhost/
    ProxyPassReverse / http://localhost/

</VirtualHost>

我们还使用了ports.conf文件

Listen 80

<IfModule ssl_module>
    Listen 443
    Listen 3000
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
    Listen 3000
</IfModule>

一个奇怪的错误被记录在错误日志中,似乎来自乘客:

[Tue Jul 28 02:34:03.643772 2020] [mpm_event:notice] [pid 83335:tid 140524586486848] AH00493: SIGUSR1 received.  Doing graceful restart

[ 2020-07-28 02:34:03.6459 113041/7ffaa7ce4700 age/Ust/UstRouterMain.cpp:421 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2020-07-28 02:34:03.6459 113041/7ffaa7dd7e40 age/Ust/UstRouterMain.cpp:491 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2020-07-28 02:34:03.6460 113041/7ffaa7462700 Ser/Server.h:816 ]: [UstRouterApiServer] Freed 0 spare client objects
[ 2020-07-28 02:34:03.6460 113041/7ffaa7462700 Ser/HttpServer.h:962 ]: [UstRouterApiServer] Freed 0 spare request objects
[ 2020-07-28 02:34:03.6460 113041/7ffaa7462700 Ser/Server.h:464 ]: [UstRouterApiServer] Shutdown finished
[ 2020-07-28 02:34:03.6460 113041/7ffaa7dd7e40 age/Ust/UstRouterMain.cpp:508 ]: All clients have now disconnected. Proceeding with graceful shutdown
[ 2020-07-28 02:34:03.6462 113041/7ffaa7ce4700 Ser/Server.h:816 ]: [UstRouter] Freed 0 spare client objects
[ 2020-07-28 02:34:03.6462 113041/7ffaa7ce4700 Ser/Server.h:464 ]: [UstRouter] Shutdown finished
[ 2020-07-28 02:34:03.6464 113041/7ffaa7dd7e40 age/Ust/UstRouterMain.cpp:523 ]: Passenger UstRouter shutdown finished

[ 2020-07-28 02:34:03.6490 113036/7f0fd67e1700 age/Cor/CoreMain.cpp:531 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2020-07-28 02:34:03.6491 113036/7f0fd711ce40 age/Cor/CoreMain.cpp:900 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2020-07-28 02:34:03.6492 113036/7f0fd711ce40 age/Cor/CoreMain.cpp:818 ]: Checking whether to disconnect long-running connections for process 113329, application /var/www/sites/cloud.myapp.com/current (vapor)
[ 2020-07-28 02:34:03.6494 113036/7f0fd5f5f700 Ser/Server.h:816 ]: [ServerThr.2] Freed 128 spare client objects
[ 2020-07-28 02:34:03.6494 113036/7f0fd5f5f700 Ser/HttpServer.h:962 ]: [ServerThr.2] Freed 1 spare request objects
[ 2020-07-28 02:34:03.6494 113036/7f0fd5f5f700 Ser/Server.h:464 ]: [ServerThr.2] Shutdown finished
[ 2020-07-28 02:34:03.6496 113036/7f0fd56dd700 Ser/Server.h:816 ]: [ApiServer] Freed 0 spare client objects
[ 2020-07-28 02:34:03.6496 113036/7f0fd56dd700 Ser/HttpServer.h:962 ]: [ApiServer] Freed 0 spare request objects
[ 2020-07-28 02:34:03.6496 113036/7f0fd56dd700 Ser/Server.h:464 ]: [ApiServer] Shutdown finished
[ 2020-07-28 02:34:03.6500 113036/7f0fd67e1700 Ser/Server.h:816 ]: [ServerThr.1] Freed 128 spare client objects
[ 2020-07-28 02:34:03.6501 113036/7f0fd67e1700 Ser/HttpServer.h:962 ]: [ServerThr.1] Freed 1 spare request objects
[ 2020-07-28 02:34:03.6501 113036/7f0fd67e1700 Ser/Server.h:464 ]: [ServerThr.1] Shutdown finished
[ 2020-07-28 02:34:03.6502 113036/7f0fd711ce40 age/Cor/CoreMain.cpp:926 ]: All clients have now disconnected. Proceeding with graceful shutdown
[ 2020-07-28 02:34:03.6503 113036/7f0fd711ce40 age/Cor/CoreMain.cpp:818 ]: Checking whether to disconnect long-running connections for process 113329, application /var/www/sites/cloud.myapp.com/current (vapor)
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 2001:4801:7825:103:be76:4eff:fe10:3795. Set the 'ServerName' directive globally to suppress this message
[ 2020-07-28 02:34:03.6885 113736/7ff19fd5ce40 age/Wat/WatchdogMain.cpp:1291 ]: Starting Passenger watchdog...
[ 2020-07-28 02:34:03.7022 113739/7f3609cfbe40 age/Cor/CoreMain.cpp:982 ]: Starting Passenger core...
[ 2020-07-28 02:34:03.7025 113739/7f3609cfbe40 age/Cor/CoreMain.cpp:235 ]: Passenger core running in multi-application mode.
[ 2020-07-28 02:34:03.7042 113739/7f3609cfbe40 age/Cor/CoreMain.cpp:732 ]: Passenger core online, PID 113739
[ 2020-07-28 02:34:03.7187 113744/7fc21a4bae40 age/Ust/UstRouterMain.cpp:529 ]: Starting Passenger UstRouter...
[ 2020-07-28 02:34:03.7199 113744/7fc21a4bae40 age/Ust/UstRouterMain.cpp:342 ]: Passenger UstRouter online, PID 113744
[Tue Jul 28 02:34:03.720634 2020] [mpm_event:notice] [pid 83335:tid 140524586486848] AH00489: Apache/2.4.43 (Ubuntu) OpenSSL/1.1.1f Phusion_Passenger/5.0.30 configured -- resuming normal operations
[Tue Jul 28 02:34:03.720659 2020] [core:notice] [pid 83335:tid 140524586486848] AH00094: Command line: '/usr/sbin/apache2'
[ 2020-07-28 02:34:03.7227 113736/7ff19fd5ce40 age/Wat/WatchdogMain.cpp:1337 ]: All Phusion Passenger agents started!
[ 2020-07-28 02:34:03.9861 113036/7f0fd711ce40 age/Cor/CoreMain.cpp:967 ]: Passenger core shutdown finished
App 113897 stdout: 
App 113897 stderr: /var/www/sites/cloud.myapp.com/releases/20200727225133/app/jobs/ga_stats_job.rb:4: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
App 113897 stderr: /usr/bin/passenger-config:27:in `require'
App 113897 stderr: : 
App 113897 stderr: cannot load such file -- phusion_passenger
App 113897 stderr:  (
App 113897 stderr: LoadError
App 113897 stderr: )
App 113897 stderr:  from /usr/bin/passenger-config:27:in `<main>'
[ 2020-07-28 02:34:13.0702 113739/7f360823b700 age/Cor/Spa/SmartSpawner.h:318 ]: Preloader for /var/www/sites/cloud.myapp.com/current started on PID 113897, listening on unix:/tmp/passenger.nZQTGV9/apps.s/preloader.f61rx3
App 114004 stdout: 

该文件包含以下代码:

require 'google/apis/analyticsreporting_v4'

require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

class GaStatsJob < StatsJob
  GA = Google::Apis::AnalyticsreportingV4
 ...

0 个答案:

没有答案