Image URL gives 404 on nginx

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
Hi, i just installed a test site to experience and learn about nginx. i have always been an apache person.

I got all the rules right, the website is working fine except for 1 issue.

Any image uploads, the URL i get is in the form of: http://www.website.com/abc/image.jpg and i get 404 when i open this URL.

If i open up http://www.website.com/abc/, the image opens up fine, the filename at the end of URL seems to be the problem .....

All other files are working fine, i get the download page, etc. just the images are giving issue. I dont run the imageviewer plugin on this site either. Not sure what i got wrong?

Any ideas anyone ?
 

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
I have these sections already along with all the rest (as per installation instruction that comes with the script).. Not sure what else i should add to pass the images to PHP.

Code:
location ~ \.php$ {
        	if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
        	fastcgi_pass   localhost:8002;
        	fastcgi_index  index.php;
        	fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        	include        fastcgi_params;
		}
        location / {
        	if (!-e $request_filename) {
                rewrite ^/(.*) /index.php?_page_url=$1 last;
        	}
        	if ($host !~* ^(www)) {
          		rewrite ^/(.*)$ https://www.website.com/$1 permanent;
        	}        
	    }
Thanks again.
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Hi,

Are you running pure Nginx or Nginx/Apache proxy mode?

The rules you have above include this which isn't part of our standard set:

if ($host !~* ^(www)) {
rewrite ^/(.*)$ https://www.filecad.com/$1 permanent;
}

Have you tried removing it, restarting nginx and trying again?

Thanks,
Adam.
 

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
Thanks Adam but it didnt help. i removed this line and am still getting a 404
i am running only Nginx with PHP-FPM (no apache or proxy mode)

The error log shows a static image files not being found on the server eg: 404 not found /home/website/public_html/9Gt/image.png not found.

Thanks
 

adam

Administrator
Staff member
Dec 5, 2009
2,046
108
63
Can you post the full nginx config file? I noticed you're using ssl, did you add the rules to the nginx ssl config?

Maybe test the download url on non ssl?
 

sukhman21

Member
YetiShare User
YetiShare Supporter
Jan 26, 2015
508
3
18
All working now. Apparently my nginx was crashing every now and then so had to reinstall and reconfigure. its all good now.

Thanks Adam!!