# 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:** 1\
**Showing post:** 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.

---

_[View the full topic](https://meta.discourse.org/t/generals-subfolder-recommendations-and-tips/74401)._
