502 bad gateway apache proxy multi site config


(Aashish Gangwani) #1

I have a site “forum.6figureswithchris.com” it was working fine behind a proxy port 8080 and I have apache on port 80 but suddenly it gives “502 bad gateway”

##this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed



templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "8080:80"   # http
  #- "444:443" # https

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  #db_shared_buffers: "256MB"

  ## can improve sorting performance, but adds memory usage per-connection
  #db_work_mem: "40MB"

  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed

env:
  LANG: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  #UNICORN_WORKERS: 3

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: 'forum.7figureswithchris.com'
  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'admin@epcmarketer.com,admin@6figureswithchris.com,admin@7figureswithchris.com,admin@chrisfrevillereview.com,admin@chrisfrevillereviews.com,admin@christopherfreville.com'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: host.epcmarketer.com
  #DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: admin@epcmarketer.com
  DISCOURSE_SMTP_PASSWORD: **no#**
  DISCOURSE_SMTP_ENABLE_START_TLS: false
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
# no # in password

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  #LETSENCRYPT_ACCOUNT_EMAIL: me@example.com

  ## The CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_postgres:
     - exec: sudo -u postgres createdb discourse_dbase1 || exit 0
     - exec: sudo -u postgres createdb discourse_dbase2 || exit 0
     - exec: sudo -u postgres createdb discourse_dbase3 || exit 0
     - exec: sudo -u postgres createdb discourse_dbase4 || exit 0
     - exec: sudo -u postgres createdb discourse_dbase5 || exit 0
     - exec:
          stdin: |
            grant all privileges on database discourse_dbase1 to discourse;
            grant all privileges on database discourse_dbase2 to discourse;
            grant all privileges on database discourse_dbase3 to discourse;
            grant all privileges on database discourse_dbase4 to discourse;
            grant all privileges on database discourse_dbase5 to discourse;
          cmd: sudo -u postgres psql discourse_dbase1
          raise_on_fail: false
          cmd: sudo -u postgres psql discourse_dbase2
          raise_on_fail: false
          cmd: sudo -u postgres psql discourse_dbase3
          raise_on_fail: false
          cmd: sudo -u postgres psql discourse_dbase4
          raise_on_fail: false
          cmd: sudo -u postgres psql discourse_dbase5
          raise_on_fail: false

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase1 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase1 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase1 <<< "create extension if not exists pg_trgm;"'

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase2 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase2 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase2 <<< "create extension if not exists pg_trgm;"'

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase3 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase3 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase3 <<< "create extension if not exists pg_trgm;"'

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase4 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase4 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase4 <<< "create extension if not exists pg_trgm;"'

     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase5 <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase5 <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql discourse_dbase5 <<< "create extension if not exists pg_trgm;"'
  after_code:
    - exec:
        echo: "hey!"

  before_bundle_exec:
    - file:
        path: /var/www/discourse/config/multisite.yml
        contents: |
         discourse_instance2:
           adapter: postgresql
           database: discourse_dbase2
           pool: 25
           timeout: 5000
           db_id: 2
           host_names:
             - forum.6figureswithchris.com
         discourse_instance3:
           adapter: postgresql
           database: discourse_dbase3
           pool: 25
           timeout: 5000
           db_id: 3
           host_names:
             - forum.chrisfrevillereview.com
         discourse_instance4:
           adapter: postgresql
           database: discourse_dbase4
           pool: 25
           timeout: 5000
           db_id: 4
           host_names:
             - forum.chrisfrevillereviews.com
         discourse_instance5:
           adapter: postgresql
           database: discourse_dbase5
           pool: 25
           timeout: 5000
           db_id: 5
           host_names:
             - forum.christopherfreville.com
  after_bundle_exec:
    - exec: cd /var/www/discourse && sudo -E -u discourse bundle exec rake multisite:migrate


## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"

  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  - exec: echo "End of custom commands"

Here are the outputs of “free -m” and “df -m”:
total used free shared
buff/cache available
Mem: 1873 1263 64 48 545 338
Swap: 1999 1177 822

Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/vda3          38221 27744      8514  77% /
devtmpfs             927     0       927   0% /dev
tmpfs                937     1       937   1% /dev/shm
tmpfs                937    10       928   1% /run
tmpfs                937     0       937   0% /sys/fs/cgroup
tmpfs                188     0       188   0% /run/user/0
/dev/loop0          3904   514      3186  14% /tmp
overlay            38221 27744      8514  77% /var/lib/docker/overlay2/b217295203dbf619158c49bd476d34ea83f121737016f263af1777318d43232b/merged
shm                  512     1       512   1% /var/lib/docker/containers/683ec51e28f18b77d9053e63203decaf4b8141cc0749a066f0909476c870b57c/mounts/shm

Here is a snippet of httpd.conf:

<VirtualHost 72.52.244.147:80>
ServerName forum.6figureswithchris.com
DocumentRoot /home/mercury/forum.6figureswithchris.com
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/

and here is the httpd error_log file snippet:

[Thu Jul 05 22:32:15.028092 2018] [proxy:error] [pid 46868] [client 123.201.41.40:57760] AH00898: Error reading from remote server returned by /favicon.ico, referer: http://forum.6figureswithchris.com/
[Thu Jul 05 22:32:16.034055 2018] [proxy_http:error] [pid 46868] (104)Connection reset by peer: [client 123.201.41.40:57760] AH01102: error reading status line from remote server 0.0.0.0:8080, referer: http://forum.6figureswithchris.com/
[Thu Jul 05 22:32:16.034106 2018] [proxy:error] [pid 46868] [client 123.201.41.40:57760] AH00898: Error reading from remote server returned by /502.shtml, referer: http://forum.6figureswithchris.com/

The things I have tried:
1)Rebuilding app, restarting vps, completely reinstalling everything from scratch

2)Tried adding to httpd.conf and failed with all these:
Timeout 2400
ProxyTimeout 2400
ProxyBadHeader Ignore
ProxyPass / http://0.0.0.0:8080/ retry=1 acquire=3000 timeout=600 Keepalive=On

3)./launcher cleanup
Image of error:
Screenshot_7


(Bhanu Sharma) #2

Is there a specific reason you’re using apache2 instead of nginx?

Have you checked apache2 logs to figure out what is making it angry?


(Aashish Gangwani) #3

Here are the apache logs. The apache was default in the system, so I used it. Is it possible to use nginx just for discourse alongwith apache?


(Bhanu Sharma) #4

If You have the right understanding then everything is achievable but that would just increase the complexity of the setup! I wonder why You are forwarding requests to 0.0.0.0 instead of localhost or something similar!


(Aashish Gangwani) #5

I tried

  1. my ip addrress: it gives

    [Fri Jul 06 15:39:42.586174 2018] [proxy:error] [pid 66519] (110)Connection timed out: AH00957:
    HTTP: attempt to connect to 72.52.244.147:8080 (72.52.244.147) failed

this error

  1. localhost: it gives same error as 0.0.0.0

P.S. When I modify virtualhost to 8080 instead of 80 port and access forum.6figureswithchris.com:8080 the site works! So the main error is in the port only


(Bhanu Sharma) #6

So You should consider looking at other vhosts for apache2 if some other vhost is trying to reserve the same IP:PORT if so, release the IP from that vhost and try port 80 again.


(Aashish Gangwani) #7

I just checked and found out that there are several vhosts with same ip:port but with different server names.
I deleted my vhost directive and used the one created with cpanel and added proxy code there and restarted httpd service but the results were same: 502 error


(Bhanu Sharma) #8

Ohh! Allright! I only understand now. I’m sorry but I won’t be of much help as my general troubleshooting suggestions don’t work with cpanel. I’d suggest you move your discourse to a separate server instead.


(Aashish Gangwani) #9

Ohk, thanks anyways. btw the server is centos vps and it has like 5 cpanel for 5 websites.


(Bhanu Sharma) #10

You’re running probably a very puzzled variant as in my experience there is a lot of struggle getting discourse to work on centOS let alone cpanel which is neither recommended nor easy to get going.


(Aashish Gangwani) #11

i know right. but it was working for 5 days completely ok but suddenly this error showed up. Is there any other way to check if memory is free? I read many threads saying its a memory error for sure


(Bhanu Sharma) #12

This is not a memory issue if you can get it working on an alternative port :wink:


(Aashish Gangwani) #13

Oh. Any other ideas? I am really stuck in this one I have spent 3 days completely just trying to solve this.


(Bhanu Sharma) #14

As I’ve suggested earlier, drop the idea of running it alongside cpanel

Just spin up a $5 droplet on DO and install afresh. It will be the most certainly works kind of solution I can give you right now.


(Jay Pfaffman) #15

If it was working before, I suspect it’s a Discourse problem. Have you rebuilt lately? Are you using any non-official plugins?


(Bhanu Sharma) #16

How can it be that it works fine on other ports but not on port 80 though? I suspect it’s cpanel and it’s firewall doing weird things.


(Aashish Gangwani) #17

I had rebuilt once and it caused problems. But I did a complete clean install of everything related docker and discourse exactly as I did earlier, the problem still persists.


(Aashish Gangwani) #18

yeah i think maybe firewall is blocking or apache not letting it connect on port 80 something like that


(Bhanu Sharma) #19

Apache is listening on port 80 and forwarding all requests to port 8080 to make the forum available to the rest of the world.


(Aashish Gangwani) #20

Oh. I am checking mod_proxy right now , if its misconfigured or something