Absolute URLs vs relative


(Chad) #1

Continuing the discussion from Just an HTTPS setup example with NGINX:

I found a related issue. I’m using ssh port forwarding to access the server (testing before going live). When using the editor I pasted an image into it. When the post is viewed the URL returned to the browser is

http://$DISCOURSE_HOSTNAME/uploads/....

While my browser is actually accessing the site using

http://localhost:8080/uploads/....

Yet it appears all other links are working just fine. Wondering if there is something I can do to change this behavior? Absolute URLs drive me nuts, given reverse proxies, etc…


(Sam Saffron) #2

Custom ports are not really supported throughout our code, it would be a major undertaking to get it to work perfectly.


(Chad) #3

First, I’d like to say a big thank you to you and all of the developers. The more I use discourse (about 3 days now of playing with it) the more I really like it.

I wasn’t asking to support custom ports. I was trying to say please don’t have the app store anything other than the path on the server to the item in question. Let the webserver deal with protocol (http/https), hostname(s), and the port(s).

When I pasted the image if the app had only stored “/uploads/path/to/file” then all would have worked if the webserver is setup properly.

I was viewing the site using http://localhost:8080/ and from the little testing I did all worked great, except for the image part.

Wordpress exhibits similar behavior as well, drives me nuts. I’ve seen cases with WP where I upload something using https (as admin was forced to ssl) yet visitors are allowed http including the upload, yet WP stored https for the upload and thus returns an https link back to the browser.

When I deploy discourse in a production role, it’ll be behind a load balancer/reverse proxy (nginx/varnish), so I can probably work up some rules to catch and fix these types of things. Though it’d be nice if apps wouldn’t do this in the first place.


(Kane York) #4

I believe they’re stored like that because absolute URLs are required for embedding, emails, and using a CDN for the images.

Having relative URLs would break the display of the images on the embedding site and in the email.

Example of the CDN usage: https://meta.discourse.org/posts/46977/cooked.json


(Chad) #5

I noticed email too. Though I still argue the picture/upload should be stored relative and let the output engine prepend the appropriate value.

Thankfully a reverse proxy will help. Thank you for the embedded link that may prove to be very helpful with something I’m working on.