# Subfolder with SSL and nginx reverse proxy

**URL:** https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496
**Category:** Self-hosting
**Created:** [2017年九月6日 20:04 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496 "2017-09-06T20:04:40Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月6日 20:04 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/1 "2017-09-06T20:04:41Z")

</div>

Hey guys,

I looked around but I couldn’t see a guide on how to host Discourse on [domain.com/forum](http://domain.com/forum) with SSL, using nginx as a reverse proxy. Currently, I’m running the forum on a subdomain - [forum.domain.com](http://forum.domain.com) and What I have in mind is, I’ll use nginx to secure the connection between the user and my server, and then call discourse locally unsecured via reverse proxy since they’re on the same machine, as per the latest set up tutorial.

I already have Ghost running the same way, and it works flawlessly.

This is my old location statement for the reverse proxy for [forum.domain.com](http://forum.domain.com) and it worked, though not securely.

```
# location / {
# 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;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
}

```

When I set this same proxy pass on location /forum in the main server block, I’m getting 404 errors for all assets, even though they’re being loaded via /forum/

```
location /forum {
        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;
        proxy_set_header X-Forwarded-Proto $scheme;

```

}

The error console shows these assets are missing:

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/e/7e62393466a1d5bab0a76c68464e7c4c7b799eb9.png)

Strangely enough, the 404 pages almost work consistently, but are still missing image assets:

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/c/0c25a90fa193daa86d7184fae7488af96d002146.png)

What I also notice is that when I do `discourse remap domain.com/ domain.com/forum`, there’s an error remapping theme\_fields

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/b/7b0ec8930f3b1ad1da6333c781333ccf9c3dfdf3.png)

Is there a way I can check these rows specifically and see what the problem is?

The easiest solution would be a wildcard certificate but that’s beyond my budget range at this point.

Any help would be appreciated and I do apologise if this issue was already resolved elsewhere, I just couldn’t find this specific scenario.

Update: Here’s the env variables in app.yml

```
env:
  LANG: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  UNICORN_WORKERS: 8

  ## TODO: The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: legiochristi.com
  DISCOURSE_RELATIVE_URL_ROOT: /forum

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  DOCKER_USE_HOSTNAME: true

```

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年九月6日 20:42 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/2 "2017-09-06T20:42:04Z")

</div>

Here’s what I’d suggest.

Follow this guide to setup subfolder support:

> [@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…

Next, follow this guide to setup the NGINX reverse proxy with Let’s Encrypt SSL support. You can add the offline page, or skip that part of the NGINX config:

> [@Add an offline page to display when Discourse is rebuilding or starting up](https://meta.discourse.org/t/adding-an-offline-page-when-rebuilding/45238):
>
> warning This guide is intended for advanced users, who are already using nginx outside the docker container. By following this guide you make your setup more complicated and will lose some speed benefits like HTTP2 if you’re not running Ubuntu 16.04 or later. Proceed with caution! When Discourse is rebuilding or starting up, your users will usually either see an error message from their browser… …or a not-so-nice 502 error message from Nginx: If you’re a perfectionist …

Note, I’d highly suggest ensuring that your site works completely from `example.com/forum` (the first guide above) before setting up NGINX.

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月6日 20:46 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/3 "2017-09-06T20:46:15Z")

</div>

Thanks for the reply. I tried the subfolder tutorial earlier today but it wouldn’t rebuild after I entered the run commands at the end of app.yml

```
root@legio:/var/discourse# ./launcher rebuild app
Ensuring launcher is up to date
Fetching origin
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 10 app
app
(<unknown>): did not find expected key while parsing a block mapping at line 96 column 5 -e LANG=en_US.UTF-8
YAML syntax error. Please check your containers/*.yml config files.

```

Any ideas?

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年九月6日 21:17 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/4 "2017-09-06T21:17:56Z")

</div>

That means you have a syntax error in your `app.yml` file. Try copying your `yml` into [http://www.yamllint.com/](http://www.yamllint.com/) and see what errors are thrown. If that doesn’t help, please share the file here, **making sure to remove/redact credentials.**

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月6日 21:20 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/5 "2017-09-06T21:20:29Z")

</div>

Yeah, I gathered as much, but it does build properly without the run commands from that guide.

I’ll try a few more things and get back to you with the file. If anyone else has any ideas, let me know.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年九月6日 21:50 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/6 "2017-09-06T21:50:30Z")

</div>

Just for reference, unless something changed in the last month, I used both those guides without issue (before I joined the team).

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月6日 21:55 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/7 "2017-09-06T21:55:34Z")

</div>

The thing is, I don’t think it’s necessary to use the docker ports at all. All I want to do is reverse proxy into Discourse from /forum, and have it work.

Now rebuilding the app closes my SSH session as soon as it starts chowning /var/www/discourse and it’s driving me up the wall.

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月6日 22:51 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/8 "2017-09-06T22:51:07Z")

</div>

Okay what I did was entered the app, then moved all of the assets in /var/www/discourse/public into a subdirectory called forum, then I moved back images/ and uploads/ and it all works great.

I think the issue is that the subdirectory got called for some assets, but not others.

I think this might cause an issue when I update Discourse next, but hopefully not.

I know I’m probably going full retard but I couldn’t find any other way.

---

<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: [2017年九月6日 23:15 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/9 "2017-09-06T23:15:57Z")

</div>

I strongly advise you to not run subfolder. You are signing up for a _lot_ of suffering.

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月6日 23:43 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/10 "2017-09-06T23:43:06Z")

</div>

Can’t afford a wildcard certificate at this point, otherwise I wouldn’t think about it twice. ☹

Out of curiosity though, what kind of suffering? @codinghorror

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年九月7日 01:45 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/11 "2017-09-07T01:45:48Z")

</div>

To start, as you are discovering it is substantially more work to set up. There are also many more places where something can go wrong, like SSL and your reverse proxy. Historically there have also been a fair number of subfolder specific bugs, and they are harder to debug.

You’ve mentioned “can’t afford a wildcard certificate” a few times now. Is there any reason you can’t set up Let’s Encrypt? It’s 100% free.

---

<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: [2017年九月7日 03:50 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/12 "2017-09-07T03:50:24Z")

</div>

See

> **[Wildcard Certificates Coming January 2018](https://letsencrypt.org/2017/07/06/wildcard-certificates-coming-jan-2018.html)**
>
> Update, March 13, 2018
> Wildcard certificate support is live.
> Let’s Encrypt will begin issuing wildcard certificates in January of 2018. Wildcard certificates are a commonly requested feature and we understand that there are some use cases where they...

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2017年九月7日 09:20 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/13 "2017-09-07T09:20:59Z")

</div>

Indeed. Maybe I’ll change my setup until wildcards become available with letsencrypt. 🙂

---

<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: [2018年四月17日 22:51 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/14 "2018-04-17T22:51:23Z")

</div>

Are wildcards available on Let’s Encrypt yet?

---

<div class="post-metadata">

### Author: ![Ironclad14](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ironclad14/32/120185_2.png) [@Ironclad14](https://meta.discourse.org/u/Ironclad14)
#### Post date: [2019年二月19日 17:29 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/15 "2019-02-19T17:29:43Z")

</div>

Yup 😛

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2019年三月21日 17:29 UTC](https://meta.discourse.org/t/subfolder-with-ssl-and-nginx-reverse-proxy/69496/16 "2019-03-21T17:29:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
