简体   繁体   中英

images on WordPress site are not showing up and I'm getting 404 errors for pictures only in wp-content/uploads/ folder

I'm unable to access images in wordpress. Steps taken:

set file permissions and ownership

-rw-r--r-- 1 www-data www-data 394446 Dec 25 09:10 pony.jpg
in this directory:
/srv/rufus/david_public_html/wp-content/uploads/2022/12/pony.jpg

ensure nginx is serving correctly

full ningx site conf is here

        location / {
           try_files $uri $uri/ /index.php?$args;
        }

Actual access error log:

 "GET /wp-content/uploads/2022/12/pony.jpg HTTP/2.0" 404 548 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" "-"

Any troubleshooting ideas?

My suspicion was that something is wrong with the nginx try_files directive, but I can serve images outside of the uploads directory.

For example, I tried:

try_files $uri $uri/ /wp-content/uploads/$uri /index.php?$args;

hoping this would try the requested URI, then the requested URI with a / appended, then the image file in the /wp-content/uploads directory, and finally the /index.php file with the $args variable appended.

However, I'm still unable to view images and asking for new ideas.

One strange thing is that I can see images loaded by the theme. For example:

-rw-r--r-- 1 www-data www-data 103639 Dec 24 23:06 david_public_html/wp-content/themes/twentytwentytwo/assets/images/flight-path-on-transparent-d.png

shows up at https://david.theboohers.org/wp-content/themes/twentytwentytwo/assets/images/flight-path-on-transparent-d.png so this may apply only to images in the uploads folder.

more specifically:

  37.134.110.4 - - [25/Dec/2022:15:53:40 +0000] "GET //wp-content/themes/twentytwentytwo/assets/images/flight-path-on-transparent-d.png HTTP/2.0" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" "-"
37.134.110.4 - - [25/Dec/2022:15:53:48 +0000] "POST /wp-admin/admin-ajax.php HTTP/2.0" 200 47 "https://david.theboohers.org/wp-admin/upload.php?item=5" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" "-"
37.134.110.4 - - [25/Dec/2022:15:54:03 +0000] "GET /wp-content/uploads/2022/12/pony.jpg HTTP/2.0" 404 548 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" "-"

Thanks for any tips and Merry Christmas.

I figured it out, but I don't really understand it.

I had a working wordpress site, so I did a diff and saw that I had this in the wp-config.php:

define('WP_MEMORY_LIMIT', '256M');

I know the WP_MEMORY_LIMIT setting in WordPress allows me to increase the maximum amount of memory that WordPress can use for different operations. This can be useful if you are experiencing issues with WordPress not being able to complete certain tasks due to insufficient memory, or if you are running a large WordPress site with many plugins and features that require a lot of memory to run properly.

But why would the existing images imported by the theme be visible but all other images wouldn't display? Anyway, this solved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM