Installation on v-server as a subfolder with other services in subfolders using apache

Hi there,

before posing configs and logs, just a basic question: I am understanding, that it should be possible to host discourse on any server that provides docker? I did not use docker before, but after installing I was able to get the sample app running, which serves a simple test website.

Is it a problem to have an apache server running on the same machine? At the end of building the app I get an error “Error response from daemon: Cannot start container […]: failed to create endpoint app on network bridge: Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use” so I thought fine, no ssl for now. But when trying to start the app it also gives the error “Error response from daemon: Cannot start container app: failed to create endpoint app on network bridge: Error starting userland proxy: listen tcp 0.0.0.0:443: bind: address already in use Error: failed to start containers: [app]” - so I guess I failed.

But where ist the problem? Apache config? Discourse config? Should there be an IP instead of “0.0.0.0” (in the output quoted above)? What about the other ports, why is there no error, but no function as well?

I would appreciate if someone could point me in the right direction. Sorry for maybe stupid question, just learning by doing and sometimes confused by documentations (especially by the apache documentation)…

Cheers!

EDIT: Changed the title to make the very helpful advice from fefrei easier to find in case someone else runs into the same trouble :wink:

Yes, there are many topics on this, try searching a bit.

1 Like

Here’s the corresponding howto:

3 Likes

Thanks! That is excactly what I needed. Should have found it by myself, sorry.
I still have issues getting NGINX running, the installation fails because of “dependency issues” maybe because apache2 is blocking port/s (“Problems to install nginx-full on debian 8”, Problems to install nginx-full on debian 8 - Unix & Linux Stack Exchange) - but this is so old it seems unlikely to be an issue on my up-to-date server…
I am a bit afraid of trying by stoping apache2 while installing NGINX. Will apache2 be able to start afterwards or will it be blocked by NGINX…?
This is all more exciting than expected… :slightly_smiling:

Hm. I’d think that a port being taken should not prevent the installation… but whatever: Just try stopping Apache and complete the installation. Afterwards, you can still stop nginx and restart Apache, then take all you time to configure nginx as needed.

Ok, after stoping apache2 the installation worked fine and nginx was running, but it blocked apache2. Stoping nginx and restarting apache2 worked, but restarting nginx fails as long as apache2 is running.

Good! Now that both are installed, you can configure them as you want.

The basic plan of attack (if you want to follow my recommendation) is this:

  1. Teach Apache to listen on another port, leaving port 80 (and maybe 443 for SSL) free. If Apache has been doing SSL for you so far, dismiss Apache of this duty.
  2. Get nginx to listen on port 80 (and maybe 443). nginx will also handle SSL if needed.
  3. Teach nginx to sort incoming requests, and forward them to Discourse and Apache as needed.

The nginx <-> Discourse part is handled through a socket and discussed in the howto above.

For the nginx <-> Apache part, you’re a bit on your own – if you need help, we need more details (i.e. where is Discourse running, where is the remainder of your website?).

1 Like

Thanks a lot, I definitly appreciate your advice!
I wish I could continue right now, but other duties demand to postpond this project to the weekend…
I hope to get back to this tomorrow evening and hopefully my next post will be about success :wink:

1 Like

Now I spent some more time on this. I thought it makes sense first to get discourse running on nginx and then worry about integration.

I got it working halfway, but there are more difficulties: creating my first user account (for the admin) leeds to an activation link that doesn’t work. It starts with “http://http://domain…” and if i copy the link cutting the first "“http://” it gets me to a discourse site “The page you requested doesn’t exist or is private”. The login doesn’t work telling me I need to activate the account first…

Also the starting page is not working as I expected. I don’t use subdomains (as sub.domain.com), but instead domain.com/discourse (no idea how to call this). Is this a problem?

For the further part, after the basic setup is working I need to enable ssl and then I consider serving my other webservices (owncloud, dokuwiki and a very simple html website) also via nginx, as I figure it will probably be easier than negotiating between apache and nginx. Does that make sense?

1 Like

Uh, now it seems I can not get apache back online. This is a problem… :fearful:

Could rebuiding the discourse app cause this somehow? I did not touch any apache settings and while playing with this before rebuilding I could always stop ngingx and restart apache.

EDIT: I could solve this. nginx seems not to have terminated completely with “service nginx stop”, so apache could not start correctly, but after killing the nginx process it was all good. :relieved:

Yikes :open_mouth:, this is not good and looks like your nginx configuration is broken. Did you set up everything as shown in the tutorial, including the proxy_set_header directives?

This is fine if and only if you follow this howto:

Discourse needs to know it is running in a subfolder or all links will be broken; the tutorial above configures this.

If you follow the combination of this and the original howto, you should have a working Discourse as long as you stop Apache and start nginx for a moment. If this is not the case, can you post your nginx configuration files?

I’m not sure all of this works under nginx (as ownCloud needs PHP, which is not my forte). Setting up nginx to route requests to Apache should be relatively easy, I have a working setup using this apprach.

I made some progress today, now apache and nginx are both working at the same time :grinning:
For now, all my old services are available via ssl and nginx / discourse may have the http all for itself, as long as I am testing this is fine, I just need to get encryption working before inviting real people to register…
But I am stuck again rebuilding the app after configuring the subfolder support, rebuilding fails with:
(<unknown>): did not find expected key while parsing a block mapping at line 16 column 1 -e LANG=en_US.UTF-8 YAML syntax error. Please check your /var/discourse/containers/*.yml config files.
The block starting line 16 contains
`templates:

  • “templates/postgres.template.yml”
  • “templates/redis.template.yml”
  • “templates/web.template.yml”
  • “templates/sshd.template.yml”
  • “templates/web.ratelimited.template.yml”
  • “templates/web.socketed.template.yml”where I needed to delete the line- “templates/web.ssl.template.yml”and add the line- “templates/web.socketed.template.yml”`

I pasted the code block into http://www.yamllint.com/ and it was accepted, also the content of the web.socketed.template.yml was accepted, I assume cecing the other files makes no sense, since they worked before and I didn’t change them…

Can you try linting the whole file? YML is really sensitive to minor errors like indentation errors, and can break in unexpected ways if the syntax is invalid.

Sure, I pasted it here: http://pastebin.com/i7E4m8y7

For privacy reasons I changed following info to default
DISCOURSE_DEVELOPER_EMAILS
DISCOURSE_HOSTNAME

and deleted the mailsever infos (but that part worked during my first attempt without the right subfolder configuration)

Thanks for looking into it!

There seems to be missing a whitespace in the pasted code at the beginning of line 17.
I just thought that’s it, but it seems correct (two whitespace) in my local file…

That’s highly suspicious. Are you 100% certain that these are two spaces, not a single tab?

As sure as I can get, which would never be 100% though…

To confirm again, I edited the file with notepad++on my local machine, deleting the two whitespaces and the linebreak, hitting enter and adding two whitespaces manually. another copy to pastebin has the same result: http://pastebin.com/rYPc5xSg

At last, I edited the file on the server the same way, using nano, copy from there to pastebin: same strange result: http://pastebin.com/MBVPXkV5

Definitly highly suspicius, but I am out of ideas…

The last two lines of your file are not indented correctly, compared to the other parts of the run: section.

2 Likes

That was it! It works. Thank you so much!

The activation link still starts with “http://http://…”, could this be caused by discourse.conf in the nginx/conf.d? I copied it from the howto on Running other websites on the same machine as Discourse, only altering the server_name.

Or could this be caused by my nginx “sites-enabled”? The “location ~ .php$”-part ended up beeing a mix out of “How To Configure Nginx as a Reverse Proxy for Apache” (How To Configure Nginx as a Reverse Proxy for Apache | DigitalOcean) and “Running other websites on the same machine as Discourse” (Running other websites on the same machine as Discourse):

location ~ \.php$ { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:; proxy_set_header Host $http_host; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

1 Like

Ah, I didn’t catch that before:

DISCOURSE_HOSTNAME: 'http://domain.com'

That’s wrong, you shoud only include the hostname itself, i.e. domain.com.

2 Likes