Worked flawlessly first time, now getting 502 error


(Webtrend Inc) #1

First time I tried installing discourse using docker container on AWS, everything worked flawlessly. I managed to create an admin account using the console commands.

I just wanted to make sure that I can reproduce the results. So I stopped the container and deleted the images. I did not change any configuration in yml files. After bootstraping and launching, I am now getting Bad Gateway 502 error when I run the following command

curl 127.0.0.1:8080

The nginx error log shows following:

2016/08/09 23:52:37 [error] 42#42: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "127.0.0.1:8080"

I am wondering what does this error pertain to? What is running on port 3000?


(Matt Palmer) #2

The unicorn app server runs on port 3000. If it isn’t running, you’ll get that error. Not really enough info here to work out why it isn’t running, but check ./shared/app/log/rails/production.log as a first step.


(Webtrend Inc) #3

OK, this is a problem that I can reproduce.

  1. I created a brand new instance on AWS
  2. Built a new app in a docker container
  3. Everything works
  4. Introduced CDN URL in app.yml (no other changes)
  5. rebuilt the application
  6. Now 502 error with same line item in nginx error log

I cannot find ./shared/app/log/rails/production.log folder but /var/www/discourse/log/production.log shows following (nothing useful I suppose). Am I looking in the right place?

Completed 200 OK in 14ms (Views: 0.1ms | ActiveRecord: 8.3ms)
Started GET "/t/9.json?track_visit=true&forceLoad=true&_=1470848204282" for 169.57.1.202 at 2016-08-10 16:58:06 +0000
Processing by TopicsController#show as JSON
  Parameters: {"track_visit"=>"true", "forceLoad"=>"true", "_"=>"1470848204282", "id"=>"9"}
Completed 200 OK in 121ms (Views: 0.1ms | ActiveRecord: 77.9ms)
Started PUT "/t/9/clear-pin" for 169.57.1.202 at 2016-08-10 16:58:08 +0000
Processing by TopicsController#clear_pin as */*
  Parameters: {"topic_id"=>"9"}
  Rendered text template (0.0ms)
Completed 200 OK in 15ms (Views: 0.2ms | ActiveRecord: 9.8ms)

(Webtrend Inc) #4

I made some progress. I read on another thread that this perhaps might be due to rails not starting. So I went into the container and used following command to start the rails (know nothing about rails)

bundle exec rails s

I am getting a fatal error that says that it is unable to authenticate postgres credentials

=> Booting Thin
=> Rails 4.2.7 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
URGENT: FATAL:  password authentication failed for user "discourse_admeen"
FATAL:  password authentication failed for user "discourse_admeen"
 Failed to initialize site default
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

But I am able to connect to psql via command line from within the container using the password that I used in app.yml.

psql -h xxx.c7ltqlsh7k7u.us-east-1.rds.amazonaws.com -U discourse_admeen -d discourse

So why is rails giving this error? Any way to troubleshoot further?


(Webtrend Inc) #5

More progress… The password authentication error disappeared when I started rail as

sudo bundle exec rails s

but another error now

=> Booting Thin
=> Rails 4.2.7 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
URGENT: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
 Failed to initialize site default
URGENT: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
 Failed to initialize site default
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

Any ideas?


(Webtrend Inc) #6

If I do

sudo rails server

I get this error

=> Booting Thin
=> Rails 4.2.7 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
URGENT: FATAL:  password authentication failed for user "discourse_admeen"
FATAL:  password authentication failed for user "discourse_admeen"
 Failed to initialize site default
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

I hope I am going on the right track here. Can anyone chime in? I know absolutely nothing about Rails.


(Matt Palmer) #7

Your database is misconfigured. It appears to want to connect to the local postgres database, rather than the RDS instance you appear to want to connect to.


(Webtrend Inc) #8

Thanks Matt for the quick response.

But where does this db configuration lie? The only place I am aware of is the web-only.yml which has been renamed by me as app.yml.

app.yml is configured correctly and as I said in my previous message, the first build worked flawlessly and I was able to create all the tables in RDS Postgres instance.

It was only during the subsequent build that things went haywire (without me changing any database configuration in app.yml).

What should I do to fix this?


(Matt Palmer) #9

Fix the configuration to provide the correct database details. Be careful to correctly quote/escape special characters in the password.


(Webtrend Inc) #10

@mpalmer you nailed it!

It was due to special chars in the password. I can’t believe I wasted so much time for this simple issue. But many thanks for your support.