# Generals Subfolder recommendations and tips

**URL:** https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401
**Category:** Self-hosting
**Created:** [September 20, 2016, 9:39pm UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401 "2016-09-20T21:39:44Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jmg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmg/32/121440_2.png) [@jmg](https://meta.discourse.org/u/jmg)
#### Post date: [September 20, 2016, 9:39pm UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/1 "2016-09-20T21:39:44Z")

</div>

The _app.yml_ changes currently described in this _subfolder support_ how-to, that complements the [normal installation](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md), have indeed helped me to install Discourse as a subfolder like _[example.com/forum](http://example.com/forum)_ instead of subdomain _[forum.example.com](http://forum.example.com)_ when suitable.

However, there was still the problem of port conflict (80, 443), and I had to shut down the rest of the site at _[example.com](http://example.com)_ (WordPress) on the same virtual server (by stopping its Nginx in my case) to be able to run Discourse at _[example.com/forum](http://example.com/forum)_, or vice versa.

For example, the how-to [Running other websites on the same machine as Discourse](https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247) is for a similar but different case, with subdomain _[forum.example.com](http://forum.example.com)_ and other domains on the server, instead of Discourse as part of a site in the same domain.

The solution for this one-server subfolder problem was hidden in a [link](http://www.benjaminroesner.com/blog/install-discourse-with-docker-in-subfolder-with-ssl-and-serve-other-content-under-the-same-domain/) from a [multi-server subfolder](https://meta.discourse.org/t/discourse-in-a-subfolder-multiple-servers-sharing-a-domain/30514/8) how-to thread. That is, using -in the Nginx configuration- a _location /forum/_ directive for the Discourse folder, and _location /_ for the rest of the site. This has worked well.

In summary, the main additional installation steps for this case (Nginx, Discourse in subfolder, rest of the site in the same domain and same server), adapted from the mentioned sources, would be the following, of course trying this first on a dev or test server:

Edit the file _/var/discourse/discourse-setup_ to comment out two lines:

```
# check_ports

# ./launcher bootstrap $app_name && ./launcher start $app_name

```

In this way, _discourse-setup_ just creates a file for Docker _/var/discourse/containers/app.yml_ that can be customized (and then used to bootstrap or rebuild) like in the [first post](https://meta.discourse.org/t/subfolder-support-with-docker/30507/1) of this _subfolder support_ how-to, with the additional changes:

Add this line:

```
templates:
  ...
  - "templates/web.socketed.template.yml"

```

Comment out these two lines:

```
expose:
# - "80:80" # http
# - "443:443" # https

```

And modify as said (after making a backup) the Nginx configuration file of our existing non-Discourse rest of the site, possibly _/etc/nginx/sites-available/example.com_ (with symlink _/etc/nginx/sites-enabled/example.com_).

This is done by just moving the Nginx configuration of the existing site into a _location /_ directive, and adding a _location /forum/_ block (using Unix socket file instead of ports) for the Discourse folder.

A simple example for http without SSL, in this particular case using Virtualmin, would be the following (https with SSL is similar but a little more complex than this example):

```
server {
    server_name example.com www.example.com;
    listen 127.0.0.10;

# Configuration for Discourse subfolder.
    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;
    }

# Configuration for the rest of the site.
    location / {
        root /srv/www/example/public_html;
        index index.html index.htm index.php;
        access_log /var/log/virtualmin/example.com_access_log;
        error_log /var/log/virtualmin/example.com_error_log;
        fastcgi_param GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param SERVER_SOFTWARE nginx;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param SCRIPT_FILENAME /srv/www/example/public_html$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param REQUEST_URI $request_uri;
        fastcgi_param DOCUMENT_URI $document_uri;
        fastcgi_param DOCUMENT_ROOT /srv/www/example/public_html;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;
        fastcgi_param HTTPS $https;
        include /srv/www/example/public_html/nginx.conf;
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/php-nginx/147000774813312.sock/socket;
        }
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
        fastcgi_read_timeout 60;
    }
}

```

Remember to test the modified Nginx configuration:

```
sudo nginx -t

```

and correct it before reloading Nginx and bootstrapping or rebuilding the Discourse container.

---

<div class="post-metadata">

### Author: ![jmg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmg/32/121440_2.png) [@jmg](https://meta.discourse.org/u/jmg)
#### Post date: [September 26, 2016, 9:05am UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/2 "2016-09-26T09:05:13Z")

</div>

And an Nginx example (file _/etc/nginx/sites-available/example.com_) that seems to be working well for Discourse subfolder (/forum), WordPress site on the same server (root), and _https_ (with SSL/TLS), including permanent redirections _http → https_, and _www. → non-www._:

```
server {
  listen 127.0.0.10:80;
  server_name www.example.com;
  return 301 https://example.com$request_uri;
}

server {
  listen 127.0.0.10:443 ssl;
  server_name www.example.com;
  ssl_certificate /srv/www/example/ssl.cert;
  ssl_certificate_key /srv/www/example/ssl.key;
  return 301 https://example.com$request_uri;
}

server {
  listen 127.0.0.10:80 default_server;
  server_name example.com;
  return 301 https://example.com$request_uri;
}

server {
  listen 127.0.0.10:443 default_server ssl;
  server_name example.com;
  ssl_certificate /srv/www/example/ssl.cert;
  ssl_certificate_key /srv/www/example/ssl.key;

  # Configuration for the Discourse subfolder /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;
  }

  # Configuration for the rest of the site (WordPress)
  location / {
    root /srv/www/example/public_html;
    index index.html index.htm index.php;
    access_log /var/log/virtualmin/example.com_access_log;
    error_log /var/log/virtualmin/example.com_error_log;
    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_param SCRIPT_FILENAME /srv/www/example/public_html$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT /srv/www/example/public_html;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;
    fastcgi_param HTTPS $https;
    include /srv/www/example/public_html/nginx.conf;
    location ~ \.php$ {
      try_files $uri =404;
      fastcgi_pass unix:/var/php-nginx/147000774813312.sock/socket;
    }
    if (!-e $request_filename) {
      rewrite ^.*$ /index.php last;
    }
    fastcgi_read_timeout 60;
  }
}

```

---

<div class="post-metadata">

### Author: ![jmg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmg/32/121440_2.png) [@jmg](https://meta.discourse.org/u/jmg)
#### Post date: [September 26, 2016, 4:50pm UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/3 "2016-09-26T16:50:19Z")

</div>

Since [Nginx 1.9.5](https://www.nginx.com/blog/nginx-1-9-5/), we can increase speed by enabling HTTP/2 for SSL, adding _“http2”_ to the _listen_ directives. For the previous example:

```
listen 127.0.0.10:443 ssl http2;

```

(…)

```
listen 127.0.0.10:443 default_server ssl http2;

```

---

<div class="post-metadata">

### Author: ![honggian](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/honggian/32/237166_2.png) [@honggian](https://meta.discourse.org/u/honggian)
#### Post date: [October 31, 2016, 5:34am UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/4 "2016-10-31T05:34:05Z")

</div>

Hello jmg

I installed discourse in the Ubuntu 14.04 LTS 64 bit, EasyEngine(Wordpress framework, php7 and lets encrypt)

Installationa have no problem but I couldn’t login through discourse, so I need comment for solving problem. How can I use discourse subfolder without any problem?

I can access through radioheaven.co.kr/forum but the initial page have so image like normal installation. And I can’t activate the account by the process.

Thank you so much of your comment!

vi /var/discourse/containers/app.yml

```
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  - "templates/web.letsencrypt.ssl.template.yml"
  - "templates/web.socketed.template.yml"

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

params:
  db_default_text_search_config: "pg_catalog.english"
  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  db_shared_buffers: "256MB"

  ## can improve 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

  ## 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: 4

  ## TODO: The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: 'radioheaven.co.kr'
  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

  ## 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: 'angel@radioheaven.co.kr'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com # required
  DISCOURSE_SMTP_PORT: 587 # (optional, default 587)
  DISCOURSE_SMTP_USER_NAME: radioheaven.co.kr # required
  DISCOURSE_SMTP_PASSWORD: password # required, WARNING the char '#' in pw can cause problems!
  #DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  LETSENCRYPT_ACCOUNT_EMAIL: angel@radioheaven.co.kr

  ## The CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

## The Docker container is 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

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  - exec:
      cd: $home
      cmd:
        - mkdir -p public/forum
        - cd public/forum && ln -s ../uploads && ln -s ../backups
  - replace:
     global: true
     filename: /etc/nginx/conf.d/discourse.conf
     from: proxy_pass http://discourse;
     to: |
        rewrite ^/(.*)$ /forum/$1 break;
        proxy_pass http://discourse;
  - replace:
     filename: /etc/nginx/conf.d/discourse.conf
     from: etag off;
     to: |
        etag off;
        location /forum {
           rewrite ^/forum/?(.*)$ /$1;
        }
  - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: $proxy_add_x_forwarded_for
       to: $http_fastly_client_ip
       global: true
## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  - exec: echo "End of custom commands"

```

vi /etc/nginx/sites-available/radioheaven.co.kr

> server {

> ```
> server_name radioheaven.co.kr www.radioheaven.co.kr;
> 
> ```

> ```
> access_log /var/log/nginx/radioheaven.co.kr.access.log rt_cache;
> error_log /var/log/nginx/radioheaven.co.kr.error.log;
> 
> ```

> ```
> root /var/www/radioheaven.co.kr/htdocs;
> 
> ```

> ```
> index index.php index.html index.htm;
> include common/php7.conf;
> include common/wpcommon-php7.conf;
> include common/locations-php7.conf;
> include /var/www/radioheaven.co.kr/conf/nginx/*.conf;
> 
> ```
> 
> }

vi /var/www/radioheaven.co.kr/conf/nginx/discourse.conf

> # Configuration for the Discourse subfolder /forum
> 
> location /forum/ {  
> proxy\_pass [http://unix](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;  
> }

Please check the attached file for result! When I click the “Click here to activate your account” button, nothing happened!

 ![](https://global.discourse-cdn.com/meta/original/3X/6/5/65c43a8939a1d94548e4021d909f3280a4bdb36f.png) ![](https://global.discourse-cdn.com/meta/original/3X/4/5/45f76ba5da8db8a8e4a071810f97bed282356bfb.png) ![](https://global.discourse-cdn.com/meta/original/3X/8/5/85aaf65852e7839aec29c0d3039e9ab2246ccd32.png) ![](https://global.discourse-cdn.com/meta/original/3X/2/8/28b0cd121725d37a27b4d51d9d71f54c64bba2bc.png) ![](https://global.discourse-cdn.com/meta/original/3X/2/b/2bd4396c55778fc859624e38dee3d62f8b6f8d54.png)

---

<div class="post-metadata">

### Author: ![jmg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmg/32/121440_2.png) [@jmg](https://meta.discourse.org/u/jmg)
#### Post date: [October 31, 2016, 6:48pm UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/5 "2016-10-31T18:48:19Z")

</div>

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/67):
>
> Installations have no problem but I couldn’t login through discourse (…) I can’t activate the account by the process.

Maybe email is not yet configured. See [Recommended Email Providers for Discourse](https://github.com/discourse/discourse/blob/master/docs/INSTALL-email.md).

---

<div class="post-metadata">

### Author: ![honggian](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/honggian/32/237166_2.png) [@honggian](https://meta.discourse.org/u/honggian)
#### Post date: [November 1, 2016, 1:35am UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/6 "2016-11-01T01:35:51Z")

</div>

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/68):
>
> Maybe email is not yet configured. See Recommended Email Providers for Discourse.

I am using Mandrill from MailChimp for Discourse. In your link, they didn’t recommend Mandrill. Does Mandrill have some problem to connect with Discourse?

I couldn’t understand why I couldn’t see any image except the message. When I install the discourse as full domain, I can see the image without no problems.

Sincerely,

Honggi An

---

<div class="post-metadata">

### Author: ![jmg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmg/32/121440_2.png) [@jmg](https://meta.discourse.org/u/jmg)
#### Post date: [November 1, 2016, 10:53am UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/7 "2016-11-01T10:53:30Z")

</div>

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/69):
>
> I am using Mandrill from MailChimp for Discourse. In your link, they didn’t recommend Mandrill. Does Mandrill have some problem to connect with Discourse?

I’m not using Mandrill, but SparkPost is working fine for me with Discourse. However, Mandrill should work. Look in your spam folders, just in case.

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/69):
>
> I couldn’t understand why I couldn’t see any image except the message. When I install the discourse as full domain, I can see the image without no problems.

Did you follow all the steps in the first post of this howto, including _long polling base url_, etc.?

---

<div class="post-metadata">

### Author: ![honggian](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/honggian/32/237166_2.png) [@honggian](https://meta.discourse.org/u/honggian)
#### Post date: [November 1, 2016, 11:22am UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/8 "2016-11-01T11:22:20Z")

</div>

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/70):
>
> I’m not using Mandrill, but SparkPost is working fine for me with Discourse. However, Mandrill should work. Look in your spam folders, just in case.

No, receiving e-mail no problem, but the activation is not working properly in my discourse.

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/70):
>
> Did you follow all the steps in the first post of this howto, including long polling base url, etc.?

Should I follow long polling base url in the first installation?

---

<div class="post-metadata">

### Author: ![jmg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmg/32/121440_2.png) [@jmg](https://meta.discourse.org/u/jmg)
#### Post date: [November 1, 2016, 5:35pm UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/9 "2016-11-01T17:35:33Z")

</div>

> [@Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/serve-discourse-from-a-subfolder-path-prefix-instead-of-a-subdomain/30507/71):
>
> Should I follow long polling base url in the first installation?

That setting is needed for all subfolder installations.

---

<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: [January 12, 2020, 8:02pm UTC](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401/10 "2020-01-12T20:02:15Z")

</div>


