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

**URL:** https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731
**Category:** Self-hosting
**Created:** [17 Febbraio 2016, 12:33pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731 "2016-02-17T12:33:08Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [17 Febbraio 2016, 12:33pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/1 "2016-02-17T12:33:08Z")

</div>

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 😉

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [17 Febbraio 2016, 4:59pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/2 "2016-02-17T16:59:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [17 Febbraio 2016, 9:28pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/3 "2016-02-17T21:28:56Z")

</div>

Here’s the corresponding howto:

> [@Run other websites on the same machine as Discourse](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247):
>
> @pfaffman edited this heavily 2022.02.24. Blame me if it’s broken. If you want to run other websites on the same machine as Discourse, you need to set up an extra NGINX or HAProxy proxy in front of the Docker container. NOTE: This is for advanced admins This guide assumes you already have Discourse working - if you don’t, it may be hard to tell whether or not the configuration is working. You cannot use ./discourse-setup to set up Discourse if another server is using port 80 or 443. You will…

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [18 Febbraio 2016, 11:17am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/4 "2016-02-18T11:17:45Z")

</div>

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”, [https://unix.stackexchange.com/questions/153980/problems-to-install-nginx-full-on-debian-8](https://unix.stackexchange.com/questions/153980/problems-to-install-nginx-full-on-debian-8)) - 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… 🙂

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [18 Febbraio 2016, 11:21am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/5 "2016-02-18T11:21:01Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [18 Febbraio 2016, 11:29am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/6 "2016-02-18T11:29:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [18 Febbraio 2016, 11:36am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/7 "2016-02-18T11:36:02Z")

</div>

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?).

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [18 Febbraio 2016, 11:53am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/8 "2016-02-18T11:53:12Z")

</div>

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 😉

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [20 Febbraio 2016, 3:33pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/9 "2016-02-20T15:33:50Z")

</div>

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](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](http://sub.domain.com)), but instead [domain.com/discourse](http://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?

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [20 Febbraio 2016, 3:49pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/10 "2016-02-20T15:49:27Z")

</div>

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

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. 😌

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [20 Febbraio 2016, 5:26pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/11 "2016-02-20T17:26:23Z")

</div>

> [@JohnDoe1](#):
>
> 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](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…

Yikes 😮, 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?

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

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

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/subfolder-support-with-docker/30507):
>
> warning Discourse Official Statement about Subfolder setup We support subfolder setups for our hosted customers at the enterprise level and up. Due to heavy technical setup complexity we strongly recommend you do not use this setup unless you are very experienced in custom subfolder setups. It is critical you have a deep understanding of NGINX setup in the Discourse Docker container Secure original IP forwarding using custom headers in the proxy chain Rate limiting in front proxy server I…

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](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247) 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?

> [@JohnDoe1](#):
>
> 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?

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.

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [21 Febbraio 2016, 12:11pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/12 "2016-02-21T12:11:26Z")

</div>

I made some progress today, now apache and nginx are both working at the same time 😀  
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/](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…

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [21 Febbraio 2016, 12:23pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/13 "2016-02-21T12:23:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [21 Febbraio 2016, 1:02pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/14 "2016-02-21T13:02:54Z")

</div>

Sure, I pasted it here: [http://pastebin.com/i7E4m8y7](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!

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [21 Febbraio 2016, 1:12pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/15 "2016-02-21T13:12:04Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [21 Febbraio 2016, 1:29pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/16 "2016-02-21T13:29:22Z")

</div>

> [@JohnDoe1](#):
>
> 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?

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [21 Febbraio 2016, 1:54pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/17 "2016-02-21T13:54:26Z")

</div>

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](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](http://pastebin.com/MBVPXkV5)

Definitly highly suspicius, but I am out of ideas…

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [21 Febbraio 2016, 2:11pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/18 "2016-02-21T14:11:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JohnDoe1](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@JohnDoe1](https://meta.discourse.org/u/JohnDoe1)
#### Post date: [21 Febbraio 2016, 2:49pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/19 "2016-02-21T14:49:39Z")

</div>

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

The activation link still starts with “[http://http](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” ([https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-for-apache](https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-for-apache)) and “Running other websites on the same machine as Discourse” ([Run other websites on the same machine as Discourse](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247)):

`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; }`

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [21 Febbraio 2016, 3:06pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/20 "2016-02-21T15:06:39Z")

</div>

> [@JohnDoe1](#):
>
> The activation link still starts with “[http://http](http://http)://…”, could this be caused by discourse.conf in the nginx/conf.d?

Ah, I didn’t catch that before:

```plaintext
DISCOURSE_HOSTNAME: 'http://domain.com'

```

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

[Next page](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731.md?page=2)
