如何在cPanel上使用RedMine解决ERR_TOO_MANY_REDIRECTS

时间:2016-03-27 17:42:47

标签: apache nginx cpanel redmine

我已经在我的cPanel Centos 6.7 Final上安装了RedMine,nGinx作为Apache 2.4上的反向代理(带乘客)。

有时候,当我尝试浏览我的Redmine时,出现ERR_TOO_MANY_REDIRECTS错误,我必须清理浏览器缓存以使其正常工作。

所以这就是问题:哪个问题可以解决? 我不太了解Ruby,Gem,Passenger,Bundler和Rake。

这是我的Redmine配置:

Environment:
  Redmine version                3.2.1.stable
  Ruby version                   2.3.0-p0 (2015-12-25) [x86_64-linux]
  Rails version                  4.2.5.2
  Environment                    production
  Database adapter               Mysql2
SCM:
  Git                            1.7.1
  Filesystem                     
Redmine plugins:
  redmine_checklists             3.1.3
  redmine_mail_reminder          3.0.0.0001

这是我的Apache(httpd)conf(相关部分):

<VirtualHost 92.222.180.93:8081>
  ServerName xxxxxxxx.xx
  ServerAlias xxxxxxxx.xx
  DocumentRoot /home/xxxxxxxx/public_html/public
  ServerAdmin webmaster@xxxxxxxx.xx
  UseCanonicalName Off
  Options -ExecCGI -Includes
  RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
  CustomLog /usr/local/apache/domlogs/xxxxxxxx.xx combined
  <IfModule log_config_module>
    <IfModule logio_module>
      CustomLog /usr/local/apache/domlogs/xxxxxxxx.xx-bytes_log "%{%s}t %I .\n%{%s}t %O ."
    </IfModule>
  </IfModule>
  ## User xxxxxxxx # Needed for Cpanel::ApacheConf
  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        UserDir enabled xxxxxxxx
      </IfModule>
    </IfModule>
  </IfModule>

  # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
  # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
  # the user's .htaccess file.  For more information, please read:
  #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
  <IfModule include_module>
    <Directory "/home/xxxxxxxx/public_html/public">
      SSILegacyExprParser On
    </Directory>
  </IfModule>

  <IfModule suphp_module>
    suPHP_UserGroup xxxxxxxx xxxxxxxx
  </IfModule>
  <IfModule !mod_disable_suexec.c>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup xxxxxxxx xxxxxxxx
    </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid xxxxxxxx xxxxxxxx
  </IfModule>
  <IfModule mpm_itk.c>
    # For more information on MPM ITK, please read:
    #   http://mpm-itk.sesse.net/
    AssignUserID xxxxxxxx xxxxxxxx
  </IfModule>


  # To customize this VirtualHost use an include file at the following location
  # Include "/usr/local/apache/conf/userdata/std/2_4/xxxxxxxx/xxxxxxxx.xx/*.conf"
</VirtualHost>

这是我的nGinx作为反向代理配置:

user  nobody;
# no need for more workers in the proxy mode
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
error_log  /var/log/nginx/error.log debug;
worker_rlimit_nofile 20480;
events {
 worker_connections 5120; # increase for busier servers
 use epoll; # you should use epoll here for Linux kernels 2.6.x
}
http {
 server_name_in_redirect off;
 server_names_hash_max_size 10240;
 server_names_hash_bucket_size 1024;
 include    mime.types;
 default_type  application/octet-stream;
 server_tokens off;
# remove/commentout disable_symlinks if_not_owner;if you get Permission denied error
# disable_symlinks if_not_owner;
 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout  5;
 gzip on;
 gzip_vary on;
 gzip_disable "MSIE [1-6]\.";
 gzip_proxied any;
 gzip_http_version 1.0;
 gzip_min_length  1000;
 gzip_comp_level  6;
 gzip_buffers  16 8k;
# You can remove image/png image/x-icon image/gif image/jpeg if you have slow CPU
 gzip_types    text/plain text/xml text/css application/x-javascript application/xml application/javascript application/xml+rss text/javascript application/atom+xml;
 ignore_invalid_headers on;
 client_header_timeout  3m;
 client_body_timeout 3m;
 send_timeout     3m;
 reset_timedout_connection on;
 connection_pool_size  256;
 client_header_buffer_size 256k;
 large_client_header_buffers 4 256k;
 client_max_body_size 200M; 
 client_body_buffer_size 128k;
 request_pool_size  32k;
 output_buffers   4 32k;
 postpone_output  1460;

###
proxy_set_header            Host                $host;
proxy_set_header            X-Real-IP           $remote_addr;
proxy_set_header            X-Forwarded-For     $proxy_add_x_forwarded_for;
###

#proxy_set_header X-Forwarded-Proto $scheme;


 proxy_temp_path  /tmp/nginx_proxy/;
 proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:15m inactive=24h max_size=500m;
 client_body_in_file_only on;
 log_format bytes_log "$msec $bytes_sent .";
 log_format custom_microcache '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $body_bytes_sent '
        '"$http_referer" "$http_user_agent" nocache:$no_cache';
include "/etc/nginx/vhosts/*";
}

这是nGinx vhost:

server 
{
  error_log /var/log/nginx/vhost-error_log warn;
  listen x.x.x.x:80;
  listen [::]:80;
  server_name xxxxxx.xx www.xxxxxx.xx;
  access_log /usr/local/apache/domlogs/xxxxxx.xx-bytes_log bytes_log;
  access_log /usr/local/apache/domlogs/xxxxxx.xx combined;
  root /home/xxxxxx/public_html/public;

  location ~*.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ 
  {
    expires 1M;
    try_files $uri @backend;
  }

  location / 
  {
    error_page 405 = @backend;
    add_header X-Cache "HIT from Backend";
    proxy_pass http://x.x.x.x:8081;
    include proxy.inc;
    include microcache.inc;
  }

  location @backend 
  {
    internal;
    proxy_pass http://x.x.x.x:8081;
    include proxy.inc;
    include microcache.inc;
  }

  location ~ .*\.(php|jsp|cgi|pl|py)?$ 
  {
    proxy_pass http://x.x.x.x:8081;
    include proxy.inc;
    include microcache.inc;
  }

  location ~ /\.ht 
  {
    deny all;
  }
}

编辑:production.log

我在发生错误之前清除了我的日志。

Started GET "/" for my.ip.my.ip at 2016-04-01 15:02:26 +0200
Processing by WelcomeController#index as HTML
  Current user: anonymous
Redirected to http://my.site.ext/login?back_url=http%3A%2F%2Fmy.site.ext%2F
Filter chain halted as :check_if_login_required rendered or redirected
Completed 302 Found in 123ms (ActiveRecord: 9.5ms)
Started GET "/login?back_url=http%3A%2F%2Fmy.site.ext%2F" for my.ip.my.ip at 2016-04-01 15:02:26 +0200
Processing by AccountController#login as HTML
  Parameters: {"back_url"=>"http://my.site.ext/"}
  Current user: anonymous
  Rendered account/login.html.erb within layouts/base (45.5ms)
Completed 200 OK in 359ms (Views: 342.8ms | ActiveRecord: 9.3ms)
Started POST "/login" for my.ip.my.ip at 2016-04-01 15:02:34 +0200
Processing by AccountController#login as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"CnO9780juQpbGCuASRL2gy7qYRG8noWBHwgx8BtgpqErMcTNhY9pJRctIqztVVKwVuwVrKeT3HkyjFfzX/c1pg==", "back_url"=>"http://my.site.ext/", "username"=>"my-username", "password"=>"[FILTERED]", "login"=>"Entra »"}
  Current user: anonymous
Successful authentication for 'my-username' from my.ip.my.ip at 2016-04-01 13:02:34 UTC

1 个答案:

答案 0 :(得分:0)

我的解决方案不正确。同样的问题。

最后我找到了解决方案。

在nginx.conf中的http块内,我将此行#proxy_set_header X-Forwarded-Proto $scheme;更改为proxy_set_header X-Forwarded-Proto http;,错误从未再次显示(从一周开始)。

这就是为什么我的nGinx作为反向代理工作,我错过了设置标题X-Forwarded-Proto。我第一次只取消注释该行,但最后我发现内部和http阻止$scheme var只能是http