# 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:** [February 17, 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:** 2

<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: [February 21, 2016, 3:54pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/21 "2016-02-21T15:54:33Z")

</div>

That was easy. Thanks again :smiley:

It seems it is working great now, the last part is to enable ssl. As I see it, I need to

1. change /etc/nginx/conf.d/discourse.conf as described in the howto on Running other websites on the same machine as Discourse.

2. Put my ssl certificate files into /var/discourse/shared/standalone/ssl/ and change the file names according to the howto

3. ? Is that it, or do I also need to make changes to nginx.conf and/or nginx/conf.d/discourse.conf?

---

<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: [February 21, 2016, 4:27pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/22 "2016-02-21T16:27:09Z")

</div>

My recommendation would be:

1. Change your current `server` block to be the block for SSL.
2. Make a new `server` block that redirects all HTTP requests to HTTPs.

For reference, here is such a redirect block:

```nginx
server {
        listen 80;
        server_name domain.com;
        return 301 https://$host$request_uri;
}

```

Here’s how the SSL configuration could look like:

```nginx
server {
        listen 443 ssl;
        server_name domain.com;

        ssl_certificate /etc/ssl/certs/cert.crt;
        ssl_trusted_certificate /etc/ssl/certs/cert.crt;
        ssl_certificate_key /etc/ssl/private/cert.key;

        ssl_ciphers "AES256+EECDH";
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;

        add_header Strict-Transport-Security "max-age=63072000;";
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;
        ssl_stapling on;
        ssl_stapling_verify on;

        client_max_body_size 20m;

        location / {
                proxy_pass http://unix:/var/discourse/shared/vorkurs/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;
                proxy_set_header X-Forwarded-Proto $scheme;
                # proxy_redirect http://vorkurs-discourse.cs.uni-saarland.de/ https://vorkurs-discourse.cs.uni-saarland.de/;
        }
}

```

* * *

Watch out: My example enables HSTS. If your site goes live with this configuration, visitors that have seen it will refuse to use http for **up to 2 years**.

---

<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: [February 21, 2016, 6:19pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/23 "2016-02-21T18:19:17Z")

</div>

Ok, your last warning made me rather try the SSL config from the howto on running other websites on the same machine as Discourse.

I have a partial success: when I enter the old http domain, it routes me to the https site and shows the correct certificate. But there is no discourse, only a bad gateway (502).

Also, I had to stop apache2 for enabling the new nginx config, probably because apache2 was still listening on port 443. So now I assume I have to change the port in the in the apache config that listens to SSL to another port, to which nginx needs to forward requests to subfolders it cannot find. How do I configure nginx to do this?

EDIT: Reading through the SSL tutorial again reminded me I needed to add the “templates/web.ssl.template.yml” which I deleted before. Rebuilding took for ever, because “Generating DH parameters” - but in the end, still the same result (bad gateway). I bet I missed to enable SSL in some config 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: [February 21, 2016, 7:22pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/24 "2016-02-21T19:22:54Z")

</div>

> [@JohnDoe1](#):
>
> EDIT: Reading through the SSL tutorial again reminded me I needed to add the “templates/web.ssl.template.yml” which I deleted before.

You don’t actually needed that, as you want the outer nginx to handle SSL, not Discourse’s internal nginx instance.

If my HSTS remark scared you off, you can just comment out the line that sets `Strict-Transport-Security` or decrease the number there to a low number of seconds.

---

<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: [February 21, 2016, 7:42pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/25 "2016-02-21T19:42:54Z")

</div>

Ah, I see. I will try with your config and “add\_header Strict-Transport-Security “max-age=60;”;” then. Restarting nginx gave me complaints about the cert now, so I am rebuilding the app again without the web.ssl.template.yml. Another 6 long minutes…

Is it correct for the same reason I do not need to expose port 443 within the app.yml, because all the port handeling happens outside of the container, or could there be an error? I deleted the lines "expose: - “80:80"” "expose: - “443:443"” and and added “templates/web.socketed.template.yml” instead (as explained in the howto on running other websites on the same machine as Discourse).

---

<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: [February 21, 2016, 7:57pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/26 "2016-02-21T19:57:26Z")

</div>

No improvement :frowning:  
The rebuild was unnecessary I guess, I should have adjusted the certificate paths. Now nginx starts correctly again, but still bad gatway on every domain and subfolder.  
Do I need to configure SSL within my nginx sites enabled? Because that I haven’t done yet…

---

<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: [February 21, 2016, 7:58pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/27 "2016-02-21T19:58:06Z")

</div>

Yes, that sounds right. You want the Discourse (and its inner nginx instance) to simply listen to normal HTTP traffic on the socket, all handling of HTTPS (and sorting traffic between Discourse and Apache) is handled by the outer nginx.

(The configurations I posted above are slightly cleaned up versions of what I run in production.)

---

<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: [February 21, 2016, 8:00pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/28 "2016-02-21T20:00:06Z")

</div>

> [@JohnDoe1](#):
>
> Now nginx starts correctly again, but still bad gatway on every domain and subfolder.

I’m a bit surprised by that. As long as you took the original port-80-configuration block and simply changed the port to 443 and added the relevant SSL options, nothing in the routing should change, i.e. you should see the same behavior, just over HTTPS instead of HTTP.

---

<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: [February 21, 2016, 8:24pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/29 "2016-02-21T20:24:57Z")

</div>

I think I got it. Embarassing to say, but I missed one path at your redirect block needed adjustment to my setup  
`proxy_pass http://unix:/var/discourse/shared/vorkurs/nginx.http.sock:;` must be  
`proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;`  
for me and it works… I have a secure discourse setup :smile:

But how do I forward the subfolders from my owncloud and dokuwiki to the apache?

---

<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: [February 22, 2016, 8:18am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/30 "2016-02-22T08:18:17Z")

</div>

Oops, I forgot to clean up that path :slightly_smiling:

As the other paths are on the same hostname as far as I understand, you want to add blocks like this to the same `server` block:

```nginx
        location /example/ {
                proxy_pass http://localhost:8080/example/;
                proxy_redirect http://domain.com/example/ https://domain.com/example/;
                proxy_redirect http://domain.com:8080/example/ https://domain.com/example/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
        }

```

You may have to experiment with these a bit, especially the `proxy_redirect` ones. You can read up details [in the nginx documentation](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect).

---

<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: [February 22, 2016, 8:51am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/31 "2016-02-22T08:51:37Z")

</div>

Ok, I need to send requests that went to

[https://domain.com/owncloud](https://domain.com/owncloud)  
[http://domain.com/owncloud](http://domain.com/owncloud)

on to the apache, I configured ports.conf as follows:

NameVirtualHost 127.0.0.1:8080  
Listen 127.0.0.1:8080

so it listens on port 8080 (and only on that, because nginx will not start if apache blocks a port that nginx wants to use).

In the nginx sites-enabled I added the following location part

```
    location /owncloud/ {
            proxy_pass http://localhost:8080/owncloud/;
            proxy_redirect http://domain.com/owncloud/ https://domain.com/owncloud/;
            proxy_redirect http://domain.com:8080/owncloud/ https://domain.com/owncloud/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
    }

```

but [https://domain.com/owncloud](https://domain.com/owncloud) and [http://domain.com/owncloud](http://domain.com/owncloud) still send me to a discourse site saying the site is not available…

---

<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: [February 22, 2016, 9:38am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/32 "2016-02-22T09:38:05Z")

</div>

Did you make sure that the location-block sending traffic to Discourse only matches the subfolder Discourse is running in?

---

<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: [February 22, 2016, 9:58am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/33 "2016-02-22T09:58:53Z")

</div>

That soulds like a good source of error for my problem. But if that is what the location part from the howto on Running other websites on the same machine as Discourse does, it is included:

```nginx
location /forum/ {
  proxy_pass https://unix:/var/discourse/shared/standalone/nginx.https.sock:;
  proxy_set_header Host $http_host;
  proxy_http_version 1.1;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} 

```

is it correct to put the discourse subfolder into the first line? It is not in the howto, but it isn’t meant for subfolder config…

---

<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: [February 22, 2016, 10:08am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/34 "2016-02-22T10:08:40Z")

</div>

> [@JohnDoe1](#):
>
> the location part from the howto on Running other websites on the same machine as Discourse does, it is included

…included in the domain config within the nginx sites-enabled, not in the nginx/conf.d/discourse.conf. Replacing the locations part there with the one mentioned above there leeds to 404 and 502 all over…

---

<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: [February 22, 2016, 10:18am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/35 "2016-02-22T10:18:30Z")

</div>

Hm, not good. Your configuration is probably too specific to debug this remotely, so here is some more general advice:

- You absolutely must configure your nginx to only route `/forum/` traffic to Discourse, or it will – surpsrise – route all traffic to Discourse.
- Because you followed the subfolder tutorial, Discourse now expects all requests to go to `/forum/somewhere`. Therefore, the outer nginx must _not_ strip the `/forum` from the request, or Discourse will rightfully respond with `404` errors.
- You can configure nginx to create quite extensive logs, which is key when debugging complex configurations :slight_smile:

Also, your `proxy_pass` directive above looks fishy: nginx should speak HTTP to Discourse, not HTTPS.

---

<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: [February 22, 2016, 10:24am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/36 "2016-02-22T10:24:24Z")

</div>

Ok, you are right, it has allready become quite specific…

Thanks a lot for your patience and walking me through to this point. I will try to figure out the rest and hopefully get back to this thread with a positive result.

Thanks again for your effort, I got the main part working thanks to you and I learned a lot, which is worth even more to me :smiley:

---

<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: [February 22, 2016, 11:13am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/37 "2016-02-22T11:13:28Z")

</div>

Sweet, it works now - all perfect :sunglasses:

One remaining problem was proxy\_pass needed to be  
[https://localhost:8080/subfolder](https://localhost:8080/subfolder) instead of  
[http://localhost:8080/subfolder](http://localhost:8080/subfolder)

And there was an apache misconfiguration (rewrite rules that enforced https before, which is now handeled by nginx)

fefrei, I would not have gotten near this far without your patient help, thank you very much!

---

<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: [February 22, 2016, 11:16am UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/38 "2016-02-22T11:16:52Z")

</div>

Thanks for reporting back!

If you want, you can post a cleaned-up version of your configuration here, in case someone else has a similar setup. :slight_smile:

---

<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: [February 23, 2016, 5:27pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/39 "2016-02-23T17:27:08Z")

</div>

Of course, that’s a good idea and the least I can do!

I attached the files to this post, because the format seems to get broken by some characters inside the files. The ending .txt must of course be deleted, but I needed to add this to be allowed to upload the files here… and the capitalized parts of the code need to be changed to the individual system.

I think all the changes I made were in these files:

- /etc/nginx/conf.d/[discours.conf.txt](https://global.discourse-cdn.com/meta/original/3X/6/1/61db17791215ef0adc45c76c2ec56721e2007fc0.txt) (2.2 KB) EDIT: A typo in this filename I cannot change. It needs to be _discourse.conf_ !
- /etc/nginx/[nginx.conf.txt](https://global.discourse-cdn.com/meta/original/3X/d/1/d1d38425d6a3fac820dc1176745214c449cb51b0.txt) (863 Bytes)
- /etc/apache2/[ports.conf.txt](https://global.discourse-cdn.com/meta/original/3X/2/a/2ae426d25491ce63d88b7e46b9bc6252e5a725f8.txt) (53 Bytes)
- /etc/apache2/sites-available/[MY\_DOMAINCOM.txt](https://global.discourse-cdn.com/meta/original/3X/1/7/1755bd5a655988938b637de7967ca1859106ec17.txt) (1.3 KB)
- /var/discourse/containers/[app.yml](https://global.discourse-cdn.com/meta/original/3X/7/5/753addd462712ee68c89e7b01a4099e5cc7b1396.yml) (3.6 KB)

I hope I this might help someone someday :wink:

Cheers!

---

<div class="post-metadata">

### Author: ![BenRoe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benroe/32/121303_2.png) [@BenRoe](https://meta.discourse.org/u/BenRoe)
#### Post date: [July 6, 2016, 3:22pm UTC](https://meta.discourse.org/t/installation-on-v-server-as-a-subfolder-with-other-services-in-subfolders-using-apache/39731/40 "2016-07-06T15:22:46Z")

</div>

Here is a solution how it works with nginx. [http://www.benjaminroesner.com/blog/install-discourse-with-docker-in-subfolder-with-ssl-and-serve-other-content-under-the-same-domain/](http://www.benjaminroesner.com/blog/install-discourse-with-docker-in-subfolder-with-ssl-and-serve-other-content-under-the-same-domain/)

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