Attachments serving locally on the server but not publicly

Problem Summary

I’m encountering a 404 error when accessing an image upload via its URL on the live Discourse site (https://techenclave.com), even though the image is present on disk and served correctly internally. I’ve rebaked the post, restarted the app, and verified internal serving works, but it still 404s externally.


What’s Working

1. Upload Exists in DB

Using the Rails console, I confirmed that the upload exists with all correct metadata:

Upload.find_by(sha1: 'a8fbe877e685e6a6994532c946c446b1279da7d2')

Output includes:

  • url: "/uploads/default/original/3X/a/8/a8fbe877e685e6a6994532c946c446b1279da7d2.jpeg"
  • Filename: IMG202506252257011.jpg
  • ID: 170265
  • Used in Post ID: 3125774

2. File Exists on Disk

Verified file is present inside the container:

ls -l /shared/uploads/default/original/3X/a/8/a8fbe877e685e6a6994532c946c446b1279da7d2.jpeg

:check_mark: File exists with correct ownership and permissions:
discourse:www-data, -rw-r--r--.


3. Symlink from Public Folder Works

The public/uploads symlink is intact:

ls -l /var/www/discourse/public/uploads
# => /shared/uploads

4. Discourse Can Serve It Internally

Tested with:

curl -I http://localhost:3000/uploads/default/original/3X/a/8/a8fbe877e685e6a6994532c946c446b1279da7d2.jpeg

Result: HTTP/1.1 200 OK


5. Post Rebaked

Rebaked the post with:

Post.find(3125774).rebake!

6. App Restarted

Ran:

./launcher restart app

Also attempted:

sudo ./launcher rebuild app

(Docker daemon was temporarily unavailable but later fixed.)


What’s Not Working

External Access to Image

Accessing:

https://techenclave.com/uploads/default/original/3X/a/8/a8fbe877e685e6a6994532c946c446b1279da7d2.jpeg

Returns:

404 Not Found

This happens across browsers and in incognito mode.


What I Need Help With

Can someone help identify what could cause:

  • A working upload that serves via localhost:3000,
  • but returns 404 externally on the public domain?

What else should I check? Any related config or logs to inspect?

Thanks in advance!

Even freshly uploaded images are not loading. Getting 404

https://techenclave.com/uploads/default/original/3X/b/3/b38f7bc7a78e572cf46f092ab67837de6f648e46.png

I guess this is not a standard install? That’s mostly all that is supported here.

How did you install discourse?

1 Like

Next time maybe mention that you very recently migrated?

Did you follow this guide when you changed from temp.techenclave.com to techenclave.com ?

2 Likes

Thank you.

The install was a standard discourse install guide on GitHub.

Yes I did a local migration on my laptop, took a backup and restored the backup on the server by uploading the file and doing a backup restore from admin panel. Should not have done that coz not all attachment files got restored despite it showing successful. Anyway did a rsync of files from local install on laptop to server to get them upto date.

Next it was a domain migration, as you rightly pointed out, from temp to root after testing the setup for a day.

The reason I did not mention the above was coz even the latest files which were being uploaded after all the above activity are also not showing. Despite a rebuild. So I did not find that info relevant.

No did not follow that guide. But when I look at it I can see that only step missed was:

  1. The old domain shows up in allowed iframe list along with the new domain in settings.
  2. remapping domain in posts which I was going to do later anyway including a rebake once this issue is resolved. The post in question was rebaked and does not have the old domain in the URL of the image.

Are these two relevant points?

Even the theme image is giving a 404.

I see the nginx logs are littered with permission denied errors for images.

Plus I see this but unable to fix the permissions. Maybe I messed up some step like ran setup with wrong user.

root@ip-172-26-0-app:/var/www/discourse# ls -ld /shared/uploads/default/optimized/3X
drwx---r-x 18 discourse www-data 4096 Jun 29 17:52 /shared/uploads/default/optimized/3X
root@ip-172-26-0-app:/var/www/discourse# ls -ld /shared/uploads/default/optimized
drwx---r-x 5 discourse www-data 4096 Jun 29 17:52 /shared/uploads/default/optimized

Edit:
Fixed it by changing directory permissions and ownership.