Error: listen tcp 0.0.0.0:80: bind: address already in use

Did you rebuild your container after changing those prefs?

./launcher destroy app
./launcher bootstrap app
./launcher start app
2 Likes

It had not occurred to me that I had to destroy the app then build it. I had been running bootstrap after stopping it instead of destroying it. You sir are a genius. Figures it would be this simple. Luckily in this whole process I learned quite a bit about nginx, Docker, etc.

I am thinking I should add a “hint” to ./launcher stop, something like:

Would you also like to remove this container? (y/N) 

Only if called with tty.

5 Likes

If you do that it would also make sense to say “why” you would want to remove the container. Eg. “this is necessary when you make changes to your app.yml, or to force an update of Discourse”.

I’m saying that because it wasn’t obvious to me at first. Like it also wasn’t obvious that destroying a container does not loose you any data.

4 Likes

@sam you should do this and fold in @naatan’s feedback. It makes sense.

To do Proxy with Apache (incase your ‘other’ Rails app is on Apache/Passenger), do the following:

<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName forum.example.com
ProxyPass / http://localhost:85/
ProxyPassReverse / http://localhost:85/
</VirtualHost>

More details here.

I cannot for the life of me figure this out. I can access my main site at gamepredict.us but cannot get my discourse at discuss.gamepredict.us. It only works at gamepredict.us:10080. Here is my nginx.conf:

upstream puma {
  server unix:///home/deploy/apps/gamepredict/shared/tmp/sockets/gamepredict-puma.sock;
}

server {
  listen 80 default_server deferred;
  server_name gamepredict.us;

  root /home/deploy/apps/gamepredict/current/public;
  access_log /home/deploy/apps/gamepredict/current/log/nginx.access.log;
  error_log /home/deploy/apps/gamepredict/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

upstream discourse {
  server 127.0.0.1:10080;
}

# configure the virtual host
server {
  # replace with your domain name
  server_name discuss.gamepredict.us;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    # pass to the upstream discourse server mentioned above
    proxy_pass http://discourse;
  }
}

And my app.yml:

## which TCP/IP ports should this container expose?
expose:
  - "10080:80"   # fwd host port 80   to container port 80 (http)
  - "2222:22" # fwd host port 2222 to container port 22 (ssh)
## TODO: The domain name this Discourse instance will respond to
DISCOURSE_HOSTNAME: 'discuss.gamepredict.us'

Any help would be very much appreciated!

You should move to the socketed Docker setup:

Thanks @riking. On this step:

expose:
  - "2222:22" # If you don't need to use ./launcher ssh app, you can remove this too

To clarify, does that mean I leave my - "10080:80" line and could remove the 2222 line if I don’t use the ssh app?

No, you remove both of them.

1 Like

Thank you very kindly for your assistance. Sorry for the need of hand-holding…

To clarify, should I also remove that whole upstream discourse section from my other nginx.conf? And then should I do a full rebuild of the docker app or is that unnecessary. Thanks.

Yeah, just rip out everything you had related to Discourse and replace it with the sample configs from the post.

Yeah, I’ve tried every combo in the book and cannot figure this out. Tried the socket method, then the proxy method that others found success with… at a loss.

Hi, I haven’t really followed the whole thread here but on occasion I have had issues where docker appears to hold on to ports and doing this prior to starting discourse has forced them to be released:
service docker restart
Kind of a big hammer solution so best to keep looking for the root cause.

1 Like

All I needed to do was point the subdomain to my digital ocean droplet. I feel so stupid. Easy fix lol. My conf was always right all along. Did not need to do anything complicated.

1 Like

Hello.
First post here :smile:

Is #85 a random number for host port or is it for a reason?
Could I use any other port number?

Thanks and sorry for bumping.

It’s random. You could use any other port that is available, as long as everything that needed to talk to that port knew where to look.

1 Like

Need to rebuild the app afterwards ?

Yes. Any change to the app.yml file needs a rebuild to take effect.

3 Likes

Sort of, env and expose are set on first creation of container, you can amend env, destroy container and start a new one to get new env (which cuts out bootstrap)