Rails 502 Error
Contents |
here for a quick overview of the site Help Center rails nginx unicorn 502 bad gateway Detailed answers to any questions you might have Meta Discuss 502 bad gateway nginx rails the workings and policies of this site About Us Learn more about Stack Overflow 502 bad gateway nginx passenger rails the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x unicorn rails Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Nginx, Unicorn and Rails = 502 Bad Gateway up vote 2 down vote favorite Im trying to setup Nginx,
Nginx Error Log
Unicorn and Rails application to work together. Nginx and Nnicorn are running, I checked that using ps command. But when trying to access my page Ive got 502 Bad Gateway Nginx error log has line: 2015/03/18 19:53:26 [error] 14319#0: *1 connect() to unix:/var/sockets/unicorn.mypage.sock failed (11: Resource temporarily unavailable) while connecting to upstream What can be the problem? my /etc/nginx/conf.d/default.conf upstream app { server unix:/var/sockets/unicorn.mypage.sock fail_timeout=0; } server { listen 80; server_name mypage.com; # Application root, as defined previously root /home/rails/mypage/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $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; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } /home/rails/mypage/config/unicorn.rb working_directory "/home/rails/mypage" pid "/home/rails/mypage/pids/unicorn.pid" stderr_path "/home/rails/mypage/log/unicorn.log" stdout_path "/home/rails/mypage/log/unicorn.log" listen "/var/sockets/unicorn.mypage.sock", backlog: 1024 worker_processes 2 timeout 30 ruby-on-rails nginx unicorn share|improve
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Very limited 502 Bad Gateway error in Rails up vote 1 down vote favorite 1 This is so weird. One of my clients has been consistently getting 502 Bad Gateway http://stackoverflow.com/questions/29133374/nginx-unicorn-and-rails-502-bad-gateway errors (without fail and in every browser), but only on one particular page of my Rails site, she can access the rest of the pages normally. Also, everybody else (including people on the same company network) can access the same page fine. Also, the production.log does not contain any trace of an error, it says the page was rendered 200 OK. What could possibly be causing this??? EDIT: I have double-checked that other Rails errors, such as trying to http://stackoverflow.com/questions/11054049/very-limited-502-bad-gateway-error-in-rails call up the details of a product id that doesn't exist, result in a 404 error instead. ruby-on-rails share|improve this question asked Jun 15 '12 at 15:45 Sprachprofi 769420 A 502 may have nothing to do with your app internally, as it indicates an invalid response was received from another server while trying to process the client's request. –cdesrosiers Jun 15 '12 at 15:54 Do you have a reverse proxy (like nginx) in front of the Rails server? If so, check those logs. –Abe Voelker Jun 15 '12 at 15:54 Have you visited the client and watched the error happen in situ? –edralph Jun 18 '12 at 12:51 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted I found it. This was an error with page headers (session object -> cookie) getting too large. I'm using Facebook authentication and was storing the Facebook user session in the session object. For this one person, her personal information on Facebook was too long, so that she was getting this error while everybody else was fine. I fixed the error by only storing the Facebook ID in the session object. share|improve this answer answered Jun 19 '12 at 8:25 Sprachprofi 769420 add a comment| up vote 1 down vote I had the similar issue for few pages alone which is weird and adding below
here for a quick overview of the site Help Center Detailed answers to any http://stackoverflow.com/questions/21414816/rails-4-nginx-unicorn-ssl-502-bad-gateway questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about https://www.digitalocean.com/community/questions/nginx-502-bad-gateway-simple-rails-app-in-centos-7-x hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow 502 bad is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Rails 4 + nginx + unicorn + ssl = 502 Bad Gateway up vote 7 down vote favorite 4 Browser is showing 502 Bad Gateway - nginx. The only good 502 bad gateway news is my SSL https and green lock is showing up. Nginx Logs Error below nginx/error.log *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xx.xx, server: mysite.com, request: "GET / HTTP/1.1", upstream: "http://xxx.xxx.xx.xxx:80/maintenance.html", host: "mysite.com" home/unicorn/log/unicorn.log (seems like it's waiting for nginx): I, [2014-01-28T17:18:37.176299 #31858] INFO -- : listening on addr=127.0.0.1:8080 fd=10 I, [2014-01-28T17:18:37.176619 #31858] INFO -- : worker=0 spawning... I, [2014-01-28T17:18:37.177379 #31858] INFO -- : worker=1 spawning... I, [2014-01-28T17:18:37.178118 #31858] INFO -- : master process ready I, [2014-01-28T17:18:37.182850 #31861] INFO -- : worker=0 spawned pid=31861 I, [2014-01-28T17:18:37.185475 #31863] INFO -- : worker=1 spawned pid=31863 I, [2014-01-28T17:18:37.186023 #31861] INFO -- : Refreshing Gem list I, [2014-01-28T17:18:37.194198 #31863] INFO -- : Refreshing Gem list I, [2014-01-28T17:18:38.484772 #31861] INFO -- : worker=0 ready I, [2014-01-28T17:18:38.501165 #31863] INFO -- : worker=1 ready Here is some of my relevant files: /etc/nginx/sites-available/default server { listen 443 default; ssl on; ssl_certificate /etc/ssl/certs/ssl-bundle.crt; ssl_certificate_key /etc/ssl/private/server.key; server_name mysite.com; root /home/username/mys
have one accepted answer. Are you sure you want to replace the current answer with this one? Yes, I'm sure. Changed your mind? You previously marked this answer as accepted. Are you sure you want to unaccept it? Yes, I'm sure. Sign Up Log In submit Tutorials Questions Projects Meetups Main Site logo-horizontal DigitalOcean Community Menu Tutorials Questions Projects Meetups Main Site Sign Up Log In submit View All Results By: frontend Subscribe Subscribed Share 0 Nginx 502 Bad Gateway simple Rails App in CentOS 7.x February 4, 2015 4.3k views In CentOS 7.x I've installed a Rails app which I can access through [ip]:8080. It works. But when I set the domain name as a server_name (instead of localhost) I get a 502 Bad Gateway problem. I already restarted nginx. And the application is running with unicorn_rails. My rails log shows nothing. PD: This app is from this tutorial. /etc/nginx/conf.d/default.conf upstream app { # Path to Unicorn SOCK file, as defined previously server unix:/tmp/unicorn.myapp.sock fail_timeout=0; } server { listen 80; server_name mydomain.com www.mydomain.com; # Application root, as defined previously root /var/www/my_app; try_files $uri/index.html $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; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } 2 comments 0 asb MOD February 4, 2015 Are you seeing anything in your Nginx error logs? /var/log/nginx/error.log Generally, a 502 error means that there is a problem with the connection between the app and the proxy server. Is the app using /tmp/unicorn.myapp.sock to communicate, does it actually exist? How To Troubleshoot Common HTTP Error CodesThis guide focuses on identifyi