Running other websites on the same machine as Discourse


(Felix Freiberger) #74

Somehow, this topic seems to be almost immune to searching – there are currently 61 posts linking to this topic, many of which are support topics that are mostly answered with a link to this howto.

Can we make this topic more visible? Maybe add a short comment with a link here?

We could even try to catch the bind: address already in use error and output something like this:


(Jeff Atwood) #75

Yeah we really really REALLY need the launcher error message to be more helpful when port 80 is in use. This was actually one of our sysadmin interview questions but we never followed up on it.

@fefrei is a million percent right. @tgxworld or @noushi, who can take this on and make it happen?


(Alan Tan) #76

I’ll take this :slightly_smiling:


(Felix Freiberger) #77

And here’s a pull request for the simple comment in standalone.yml:


(Alan Tan) #78

PR :allthethings:


(Dan Dascalescu) #79

Has anyone managed to get this to work recently? It worked for me in Oct '15, but now nginx errors with

connect() to unix:/var/discourse/shared/standalone/nginx.https.sock failed (2: No such file or directory)

They key line in the OP is the same,

proxy_pass https://unix:/var/discourse/shared/standalone/nginx.https.sock:;

So I don’t understand what happened. I also don’t understand how exactly the templates work, including web.socketed, which might be the culprit.


(Jeff Atwood) #80

Well, you seem to be making it rather complex with a lot of unusual customizations and tweaks. Most customers we set up on the $99 install do just fine even over a year or more without a lot of fuss. You are a bit different.


(Dan Dascalescu) #81

The only customization actually is that I’m trying to run nginx outside the container, in order for it to parse a map file of URLs from the MyBB forum, redirecting them to the correct Discourse threads.

I did find a lot of issues, but that was using Discourse normally (30-second install on a 1GB RAM host).

Anyway, that’s besides the point. I’m just trying to get the guide on this page to work.


(Jeff Atwood) #82

Ok I can confirm this is 100% working. When I apt-get install apache2 I can see that port 80 is definitely in use:

and after bootstrapping when I try to start Discourse, I get:

root@community:/var/discourse# ./launcher start app

Launcher has detected that port 80 is in use.

If you are trying to run Discourse simultaneously with another web server like Apache or nginx, you will need to bind to a different port.
See https://meta.discourse.org/t/17247 for help.

Great work @tgxworld and thanks again @fefrei for keeping us on top of this. (60 topics :warning: :dizzy_face: )


(chamunks) #83

I skimmed over this thread looking for examples to do this and couldn’t seem to find one.

My Problem

I have an email server and my discourse on the same machine. I’ve been trying to run Discourse since launching the email app container and have been unable to bind Discourse to the other IP address on the machine it just says port 80 is already in use.

What I’ve tried

I purchased a secondary IP address for the machine and bound the email servers web panel to the original IP associated with the server. That seems to work fine because its just a simple docker run command. The biggest problem is the Discourse launcher is having issues letting me “expose” port 80 on a specific IP address.

The error that discourse throws

Launcher has detected that port 80 is in use.

If you are trying to run Discourse simultaneously with another web server like Apache or nginx, you will need to bind to a different port.
See https://meta.discourse.org/t/17247 for help.

My slightly sanitized app.yml

## After making changes to this file, you MUST rebuild for any changes
## to take effect in your live Discourse instance:
##
## /var/discourse/launcher rebuild app
##
## Make sure to obey YAML syntax! You can use this site to help check:
## http://www.yamllint.com/

## this is the all-in-one, standalone Discourse Docker container template

# You may add rate limiting by uncommenting the web.ratelimited template.
# Out of the box it allows 12 reqs a second per ip, and 100 per minute per ip
# This is configurable by amending the params in this file

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"

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

# any extra arguments for Docker?
# docker_args:

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ##
  ## On 1GB installs set to 128MB (to leave room for other processes)
  ## on a 4GB instance you may raise to 1GB
  db_shared_buffers: "256MB"
  #
  ## Set higher on large instances it defaults to 10MB, for a 3GB install 40MB is a good default
  ## this improves 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

  ## TODO: How many concurrent web requests are supported?
  ## With 2GB we recommend 3-4 workers, with 1GB only 2
  ## If you have lots of memory, use one or two workers per logical CPU core
  UNICORN_WORKERS: 4

  ## 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: 'REDACTED'

  ## TODO: The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: 'discourse.REDACTED.net'

  ## TODO: The mailserver this Discourse instance will use
  DISCOURSE_SMTP_ADDRESS: mail.REDACTED.com         # (mandatory)
  #DISCOURSE_SMTP_PORT: 587                        # (optional)
  DISCOURSE_SMTP_USER_NAME: discourse.REDACTED.com      # (optional)
  DISCOURSE_SMTP_PASSWORD: REDACTED               # (optional, WARNING the char '#' in pw can cause problems!)
  DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)

  ## The CDN address for this Discourse instance (configured to pull)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## These containers are 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

## The docker manager plugin allows you to one-click upgrade Discourse
## http://discourse.example.com/admin/docker
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Remember, this is YAML syntax - you can only have one block with a name
run:
  - exec: echo "Beginning of custom commands"

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

  ## If you want to configure password login for root, uncomment and change:
  ## Use only one of the following lines:
  #- exec: /usr/sbin/usermod -p 'PASSWORD_HASH' root
  #- exec: /usr/sbin/usermod -p "$(mkpasswd -m sha-256 'RAW_PASSWORD')" root

  - exec: echo "End of custom commands"

(dredgerman) #84

This 100% does not work,

proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;

this folder path does not exist.

just produces bad gateway error


(Felix Freiberger) #85

This definitely works – I am running this setup on two virtual machines right now.

Did you bootstrap and start Discourse already? This file is created in the process.


(Daffy Chu) #86

would https effect it? Would I also need to change the port for https if I were to do this. Also when I rebuilt app with port like 8888:80 I don’t have to input the port in my web link, it just automatically goes to the https site.

EDIT: After a fresh install of my system again, I decided to try have this finished installing before anything. But right now I’m stuck on one part where, I’m not sure how to enable the https for discourse while having NGINX. I have followed the configuration file exactly the same as the one in this tutorial. And the config I set it to the https one, but when I view the site, I get the 502 Bad Gateway, and the error while building it is “Port 443 is already in use” Is there any other way to do this? by not implementing the 443:443 in the app.yml, I still get the same 502 Bad gateway.

Any help would be appreciated thank you

  • DC

(Felix Freiberger) #87

Did you follow this part of the initial post?

Apart from the changes there, nothing should change from the HTTP scenario, especially in app.yml.
The only other change is that you’ll want to enable the site setting use https after everything is set up.

(The idea is that the outer nginx handles HTTPS, and will forward the requests as plain HTTP to Discourse.)


(Олексей же) #88

If you are trying to run Discourse simultaneously with another web
server like Apache or nginx, you will need to bind to a different port

Where i can change port to bind? app.yml is not present in contaners dir, there is no another config file.


(Felix Freiberger) #89

Are you using the official Docker-based install?


(Олексей же) #90

Yes, there is no problem, just use old school techic: copy yml file, change it, bootstrapp an app.


(Ludovic Bellier) #92

I’ve got a problem with the ssl conf file.

My undestanding is that the web.socketed.template.yml replaces lines in th docker nginx conf file:
*listen 80 by listen socket nginx.http.sock
*listen 443 by listen socket nginx.https.sock

If I comment the web.ssl.template.yml template there is no listen 443 directive in the nginx docker conf file.
So the template web.socketed.template.yml fails to replace this line.
As the result there is no nginx.https.sock in the shared directory. The host is not able to send https traffic to the docker.

root@sandbox-app:/# grep listen /etc/nginx/conf.d/discourse.conf 
  listen unix:/shared/nginx.http.sock;
  # listen 443 ssl;
2016/05/30 11:01:42 [crit] 28085#0: *12 connect() to unix:/var/discourse/shared/standalone/nginx.https.sock failed (2: No such file or directory) while connecting to upstream, client: zzz, server: xxx, request: "GET /favicon.ico HTTP/1.1", upstream: "https://unix:/var/discourse/shared/standalone/nginx.https.sock:/favicon.ico", host: "xxx", referrer: "https://xxx/t/la-cruche-du-mois"

using the http.sock in host nginx conf file does not work

2016/05/30 11:05:47 [error] 29363#0: *13 SSL_do_handshake() failed (SSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol) while SSL handshaking to upstream, client: aaa, server: xxx, request: "GET / HTTP/1.1", upstream: "https://unix:/var/discourse/shared/standalone/nginx.http.sock:/", host: "xxx"

If I rebuild the app with web.ssl.template.yml uncommented, the docker nginx conf file has a directive for https

root@sandbox-app:/# grep listen /etc/nginx/conf.d/discourse.conf 
  listen unix:/shared/nginx.http.sock;
  listen unix:/shared/nginx.https.sock ssl http2;

(Felix Freiberger) #93

Discourse within the container doesn’t need to talk HTTPS – it’s only receiving traffic from localhost.

Just remove all HTTPS-related stuff from app.yml, and configure the outer nginx to implement HTTPS and forward the requests as needed :slight_smile:


(Ndianabasi Udonkang) #94

I think this line should read:

with the colon before semicolon (at the end of the line) removed.