Is there any way to access the public folder outside of Docker?

If you want to serve images for your Discourse site, simply upload them as attachments in any post. By default, Discourse has a restricted staff category that is ideal for this purpose. CSS and JavaScripts can be entered as customizations in the admin interface.

However, these images’ URLs won’t be very readable, so if you want to serve anything under a specific filename or upload full HTML pages, that’s going to be a problem as Discourse currently has no means to host “foreign” content. As I mentioned, you will want to run your own frontend webserver and route requests either to your own content or to the Discourse container as needed. For Apache, something like this could work, assuming that you’ve changed your Discourse container definition to map port 4000 to internal port 80:

<Proxy balancer://discourse>
    BalancerMember http://localhost:4000
</Proxy>

Alias /static/ "/home/website/htdocs/"
<Directory "/home/website/htdocs">
    Require all granted
</Directory>

RewriteEngine on
RewriteRule ^/static$ /static/ [R=301,L]
RewriteRule ^/static/(.*)$ /static/$1 [PT,L]
RewriteRule ^/(.*)$ balancer://discourse%{REQUEST_URI} [P,QSA,L]

Of course, running another webserver isn’t free, least of all in terms of time invested into its configuration, but the slight advantage is that you can now not only serve static content but also other applications such as PHP scripts.

4 Likes