The app.yml changes currently described in this subfolder support how-to, that complements the normal installation, have indeed helped me to install Discourse as a subfolder like example.com/forum instead of subdomain 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 (WordPress) on the same virtual server (by stopping its Nginx in my case) to be able to run Discourse at example.com/forum, or vice versa.
For example, the how-to Running other websites on the same machine as Discourse is for a similar but different case, with subdomain 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 from a multi-server subfolder 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 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.