0

Hey guys I've been struggling with this for the past day, and I'm in need of some assistance.

So in essence I have two images stored on my main domain and subdomain with nginx.

http://orgasmal.com/r.png (SFW)

http://assets.orgasmal.com/e.gif (SFW)

they both load fine in the browser which is good. The only problem is when I curl the main domain it returns a 404.

curl -I http://orgasmal.com/r.png
HTTP/1.1 404 Not Found
Server: nginx/1.6.3
Date: Mon, 29 Aug 2016 18:52:07 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive

But when I curl the subdomain it works as expected.

curl -I http://assets.orgasmal.com/e.gif
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Mon, 29 Aug 2016 18:53:05 GMT
Content-Type: image/gif
Content-Length: 145
Last-Modified: Mon, 29 Aug 2016 05:34:06 GMT
Connection: keep-alive
ETag: "57c3c94e-91"
Accept-Ranges: bytes

I've tried pretty much everything to try to get this to work, even the server blocks in my .conf file are the same but it still gives a 404 to the main domain image. Any help would be appreciated.

server {
    listen   80;
    server_name  orgasmal.com;

    # note that these lines are originally from the "location /" block
    root   /var/www/orgasm;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
     error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

server {
    listen   80;
    server_name  assets.orgasmal.com;

    # note that these lines are originally from the "location /" block
    root   /var/www/img;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
     error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

The directories are the same as well

drwxr-xr-x 2 nginx nginx 4096 Jul 18 11:30 cgi-bin
drwxr-xr-x 2 nginx nginx 4096 Jul 18 11:30 html
drwxr-xr-x 2 nginx nginx 4096 Aug 29 14:00 img
drwxr-xr-x 2 nginx nginx 4096 Aug 29 14:00 orgasm

EDIT

I checked out my nginx error logs and this looks like it has something to do with the issue i'm having. The 403 error is expected, but the two errors above it seem to be some sort of weird redirect that's messing it up. Not sure how to fix it, but that seems to be the problem.

2016/08/29 16:23:35 [error] 28032#0: *53 open() "/usr/share/nginx/html/r.png" failed (2: No such file or directory), client: MY IP, server: _, request: "HEAD /r.png HTTP/1.1", host: "orgasmal.com"
2016/08/29 16:24:01 [error] 28032#0: *54 open() "/usr/share/nginx/html/r.png" failed (2: No such file or directory), client: MY IP, server: _, request: "HEAD /r.png HTTP/1.1", host: "orgasmal.com"
2016/08/29 16:24:48 [error] 28032#0: *55 directory index of "/var/www/orgasm/" is forbidden, client: MY IP, server: orgasmal.com, request: "GET / HTTP/1.1", host: "orgasmal.com"

2 Answers2

0

Suspect it's your client as it works fine when I curl from my AWS server.

curl -I  http://orgasmal.com/r.png
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Mon, 29 Aug 2016 19:53:45 GMT
Content-Type: image/png
Content-Length: 224603
Last-Modified: Mon, 29 Aug 2016 17:41:59 GMT
Connection: keep-alive
ETag: "57c473e7-36d5b"
Accept-Ranges: bytes

It also works fine from webpagetest - click to see the result.

Subdomain curl works fine too. I'm not game to click the link from the PC I'm on though.

Update after logs provided

Regarding this piece of configuration

error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}

The error_page directive says "if there's a 500 error look for the 50x.html page". The location rule says "instead of looking for a static html page, look for the file requested in the /usr/share/nginx/htm directory". This log entry confirms that's what's happening.

"/usr/share/nginx/html/r.png" failed (2: No such file or directory)

It's a pretty weird bit of configuration. I'd remove it entirely and just let the error_page directive and location entirely and just let the server send back appropriate error codes when it finds errors.

Tim
  • 30,383
  • 6
  • 47
  • 77
0

What The Problem Was

This server block in /etc/nginx/nginx.conf was some how messing it up, so I deleted it and everything works perfectly now.

 server {
    listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                root   /usr/share/nginx/html;
        index  index.html index.htm;
         }

        error_page 404 /404.html;
            location = /40x.html {
        }

    error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

From my client

curl -I http://orgasmal.com/r.png
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Mon, 29 Aug 2016 21:11:53 GMT
Content-Type: image/png
Content-Length: 224603
Last-Modified: Mon, 29 Aug 2016 17:41:59 GMT
Connection: keep-alive
ETag: "57c473e7-36d5b"
Accept-Ranges: bytes
Oldskool
  • 2,005
  • 1
  • 16
  • 26