2016-05-14 131 views
0

當我嘗試訪問Digital Ocean Server上的rails應用程序時,瀏覽器中出現以下錯誤:重定向了太多次。在控制檯中:net :: ERR_TOO_MANY_REDIRECTSNginx,Unicorn,net :: ERR_TOO_MANY_REDIRECTS

此時,capistrano成功部署,沒有任何錯誤。該應用程序在本地運行完美(無錯誤)。

下面是其他相關文件,下面以nginx,unicorn和rails的錯誤日誌文件開始,下面還顯示了nginx和unicorn的配置文件。

的/ etc /默認/麒麟

CONFIGURED=yes 
TIMEOUT=60 
APP_ROOT=/home/rails/rails_project/current 
CONFIG_RB=/etc/unicorn.conf 
PID=/var/run/unicorn.pid 
RAILS_ENV="production" 
UNICORN_OPTS="-D -c $CONFIG_RB -E $RAILS_ENV" 
PATH=/home/rails/.rvm/gems/ruby-2.2.2/bin:/home/rails/.rvm/gems/[email protected]/bin$ 
export GEM_HOME=/home/rails/.rvm/gems/ruby-2.2.2 
export GEM_PATH=/home/rails/.rvm/gems/ruby-2.2.2:/home/rails/.rvm/gems/[email protected]$ 
export HOME=/home/rails 
DAEMON=/home/rails/.rvm/gems/ruby-2.2.2/bin/unicorn 

/var/log/unicorn/unicorn.log

I, [2016-05-13T22:26:59.271424 #11584] INFO -- : reaped #<Process::Status: pid 11587 exit 0> worker=0 
I, [2016-05-13T22:26:59.272911 #11584] INFO -- : reaped #<Process::Status: pid 11590 exit 0> worker=1 
I, [2016-05-13T22:26:59.273219 #11584] INFO -- : reaped #<Process::Status: pid 11592 exit 0> worker=2 
I, [2016-05-13T22:26:59.273573 #11584] INFO -- : reaped #<Process::Status: pid 11595 exit 0> worker=3 
I, [2016-05-13T22:26:59.274209 #11584] INFO -- : master complete 
I, [2016-05-13T22:27:00.664033 #12489] INFO -- : unlinking existing socket=/var/run/unicorn.sock 
I, [2016-05-13T22:27:00.664570 #12489] INFO -- : listening on addr=/var/run/unicorn.sock fd=10 
I, [2016-05-13T22:27:00.668023 #12489] INFO -- : worker=0 spawning... 
I, [2016-05-13T22:27:00.669161 #12489] INFO -- : worker=1 spawning... 
I, [2016-05-13T22:27:00.670383 #12492] INFO -- : worker=0 spawned pid=12492 
I, [2016-05-13T22:27:00.671245 #12489] INFO -- : worker=2 spawning... 
I, [2016-05-13T22:27:00.676617 #12489] INFO -- : worker=3 spawning... 
I, [2016-05-13T22:27:00.680864 #12495] INFO -- : worker=1 spawned pid=12495 
I, [2016-05-13T22:27:00.681924 #12489] INFO -- : master process ready 
I, [2016-05-13T22:27:00.689107 #12497] INFO -- : worker=2 spawned pid=12497 
I, [2016-05-13T22:27:00.696755 #12500] INFO -- : worker=3 spawned pid=12500 
I, [2016-05-13T22:27:00.802486 #12492] INFO -- : Refreshing Gem list 
I, [2016-05-13T22:27:00.804209 #12500] INFO -- : Refreshing Gem list 
I, [2016-05-13T22:27:00.807876 #12497] INFO -- : Refreshing Gem list 
I, [2016-05-13T22:27:00.811879 #12495] INFO -- : Refreshing Gem list 
I, [2016-05-13T22:27:10.403242 #12500] INFO -- : worker=3 ready 
I, [2016-05-13T22:27:10.404469 #12497] INFO -- : worker=2 ready 
I, [2016-05-13T22:27:10.406947 #12495] INFO -- : worker=1 ready 
I, [2016-05-13T22:27:10.407474 #12492] INFO -- : worker=0 ready 

/var/log/nginx/error.log

2016/05/13 21:00:18 [error] 31654#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 148.75.53.23, server: codepajamas.com, request: "GET/HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "codepajamas.com" 
2016/05/13 21:05:33 [error] 31654#0: *5 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 148.75.53.23, server: codepajamas.com, request: "GET/HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "codepajamas.com" 
2016/05/13 21:19:52 [error] 31654#0: *8 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 180.76.15.29, server: codepajamas.com, request: "GET/HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "www.codepajamas.com" 
2016/05/13 21:21:40 [error] 31654#0: *12 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 148.75.53.23, server: codepajamas.com, request: "GET/HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "codepajamas.com" 
2016/05/13 21:30:33 [error] 31654#0: *16 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 148.75.53.23, server: codepajamas.com, request: "GET/HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "codepajamas.com" 

/home/rails/rails_project/current/log/production.log

(empty) 

/etc/unicorn.conf

listen "unix:/var/run/unicorn.sock" 
worker_processes 4 
user "rails" 
working_directory "/home/rails/rails_project/current" 
pid "/var/run/unicorn.pid" 
stderr_path "/var/log/unicorn/unicorn.log" 
stdout_path "/var/log/unicorn/unicorn.log" 

/etc/nginx/nginx.conf

user www-data; 
worker_processes 4; 
pid /run/nginx.pid; 

events { 
    worker_connections 768; 
} 

http { 
    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; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    gzip on; 
    gzip_disable "msie6"; 

    text/xml application/xml application/xml+rss text/javascript; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

/etc/nginx/sites-可用/導軌

upstream app_server { 
    server unix:/var/run/unicorn.sock fail_timeout=0; 
} 

server { 
    listen 443 ssl; 
    server_name <mydomain>.com www.<mydomain>.com; 
    ssl_certificate /etc/letsencrypt/live/<mydomain>.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/<mydomain>.com/privkey.pem; 
    root /home/rails/rails_project/current/public; 
    index index.htm index.html; 

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_prefer_server_ciphers on; 
    ssl_dhparam /etc/ssl/certs/dhparam.pem; 
    ssl_ciphers <removed don't want you to see> 
    ssl_session_timeout 1d; 
    ssl_session_cache shared:SSL:50m; 
    ssl_stapling on; 
    ssl_stapling_verify on; 
    add_header Strict-Transport-Security max-age=15768000; 

    location/{ 
    try_files $uri/index.html $uri.html $uri @app; 
    } 

    location ~* ^.+\. (jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ { 
try_files $uri @app; 
    } 

    location @app { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://app_server; 
    } 

    location ~ /.well-known { 
    allow all; 
    root /usr/share/nginx/html; 
    } 
} 

server { 
    # redirect HTTP to HTTPS 
    listen 80; 
    server_name <mydomain>.com www.<mydomain>.com; 
    return 301 https://$host$request_uri; 
} 

任何幫助,非常感謝。

回答

0

好吧,經過大量的挖掘後,我發現錯誤信息試圖向我暗示我強制HTTPS並進入某種重定向循環。我只是有在配置/環境/ production.rb

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
# config.force_ssl = true 

這被註釋掉了註釋掉一條線,我必須取消註釋它。必須記住什麼時候中斷的工作先前檢查你的git diff以查看你所做的所有更改。看起來rails應用程序和nginx都試圖強制ssl這創建了一個重定向循環,不知何故不確定。這些其他職位也有幫助:

Why am I getting infinite redirect loop with force_ssl in my Rails app?

Nginx configuration leads to endless redirect loop

相關問題