Development log: 2022-10-12

2022 October 12

One limitation of Discourse is that while it allows users to upload
images, it provides no such capability for video, audio, or files one
wishes to allow to be downloaded.  You can embed media files simply
by specifying the URL, but in order to do so, you need to host the
file on another server whose URL you can embed.  This is a real bother,
since hosting a short video on YouTube is a lot of work and there are
few places that provide free hosting of other media and files.  To
remedy this, I thought I'd try setting up an Apache server on the
Scanalyst host, running alongside the Nginx server that runs Discourse,
with the Apache server using alternative ports for http: and https:

    yum install httpd
    yum install mod_ssl

to configure as for, but with port 8008 for http: and
port 591 for https:.  These are ports reserved for http-alt by IANA.
For the SSL configuration, we use the same secret key and certificate
chain as the Nginx server for Discourse.
    SSLCertificateFile /var/discourse/shared/standalone/ssl/
    SSLCertificateKeyFile /var/discourse/shared/standalone/ssl/
These files are updated automatically by the Letsencrypt cron job run
by Discourse.

The Apache server is configured to log in /server/log/httpd just as on

Set up a place holder index.html in:
to identify the server and deter trawling for content by directory

Created content directories in the Web server root:

Started the Apache server and everything worked the first time.  My
pathfinder test URL:
came up in the browser with no problems.

Tried an embed in a Sand Box post on Scanalyst and fell into a pot of
soup which consumed the rest of the day.  This is a summary as I posted
on the Discourse support forum.

    TITLE: Cannot use port number in URL to embed media in post

    In order to allow my users to host videos, audio files, etc. that
    they embed in Discourse posts, I have set up an Apache server
    running alongside the Nginx that runs Discourse. The Apache server
    runs on port 8008 for http: and port 591 for https: (IANA ports
    reserved for http-alt). This works fine and content on the server
    is accessible from browsers by specifying the port number in the
    URL, for example:

    But if you try to embed this URL in a Discourse post, it fails

        Sorry, we were unable to generate a preview for this web page,
        because the server ‘’ could not be found.
        Instead of a preview, only a link will appear in your post.

    If I run tcpdump and monitor DNS traffic, I see nothing being sent
    when it rejects this URL. It is rejecting it without ever making a
    DNS query. If I change the port number in the URL to 443, the
    default for https:, it makes the DNS query normally but the embed
    fails, of course, because the Apache server is not listening on
    that port and the Discourse server does not know what to do with
    the URL. I have seen nothing in the Discourse documentation that
    indicates embed URLs may not specify a port number.

    Looking through the source code, I found a test in function
    validate_uri_format at line 362 of lib/final_destination.rb which
        return false if @uri.scheme == 'https' && @uri.port != 443
    which appears to reject an https: URL that uses a port other than
    443. This seemed to explain what I was seeing, so I commented out
    this line, but it made no difference at all, even after I restarted
    Discourse. When the post appears on the site with the embed turned
    into a text link, clicking the text link shows the video correctly,
    so the only problem is failing to recognise it as an embed and
    wrapping the inline player around it.

    My questions are, at this point:

        * Are non-standard port numbers intended to work on URLs for
          embeds in Discourse posts?
        * If so, what is causing these URLs to be rejected?
        * Is there any way to get them to work?

    There was a discussion here in March 2017 about this issue in these
    two posts:

        * Specifying port for embeddable host given an IP results in
        * FIX: Allow ports for embed host IPs #4759 (on GitHub)

    which implied the problem had been fixed, but it does not work today on 2.9.0.beta10.

I'll see what comes of this.  At the moment, I'm stumped.

Ruby source code is in:

To dump DNS traffic, including ASCII packet contents, use:
    tcpdump -i eth0 -n -s1500 -vvv -t -X port 53

To list Discourse log:
    cd ~/discourse/image
    ./launcher logs app

To view internal log, sign on as Administrator, then: