Black nginx magic

Okay.

So I would like to know how my current shared host is doing something, because for the life of me I can't get it to work.

My host is using nginx by the way.

On my main site www.the-sps.org I'm serving all my static content from http://static.the-sps.org, to set this up all I did was create a domain alias off of www.the-sps.org, I then had to manually change the A record for the static to match the www.

Here's the black magic part, if you visit http://static.the-sps.com you get a 403 forbidden but the address does in fact server up my static content, how is this possible?

I created a record in my linode dns manage called c which would result in c.the-sps.net but when I visit that I get the full site.

CONFUSED

10 Replies

I'm guessing, no file called index.htm/html/php/whatever and directory listings turned off, which is the default nginx behavior and the default in most distro versions of nginx. No magic.

@ChemicalKicks:

how is this possible?

I would tell you but you first have to pass through rigorous training and testing and ritual ascension to our inner circle of nginx sorcerers.

Meanwhile, though, you could check your config for

server_name    _;

which basically defines "any" host request for the listening IP.

Mean-meanwhile, care to post your nginx config?

@Daevien:

I'm guessing, no file called index.htm/html/php/whatever and directory listings turned off, which is the default nginx behavior and the default in most distro versions of nginx. No magic.
So would I have to create a new directory on my server + vhost for it?

Still confused btw

@Azathoth:

@ChemicalKicks:

how is this possible?

I would tell you but you first have to pass through rigorous training and testing and ritual ascension to our inner circle of nginx sorcerers.

Meanwhile, though, you could check your config for

server_name    _;

which basically defines "any" host request for the listening IP.

Mean-meanwhile, care to post your nginx config?

server {
        if ($host = 'the-sps.net' ) {
        rewrite  ^/(.*)$  http://www.the-sps.net/$1  permanent;
}
    server_name www.the-sps.net the-sps.net;
    access_log /srv/www/the-sps.net/logs/access.log;
    error_log /srv/www/the-sps.net/logs/error.log;
    root /srv/www/the-sps.net/public_html;

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

location /internal_data/ {
    internal;
}
location /library/ {
    internal;
}

location ~ \.php$ {
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include         fastcgi_params;
}

location /phpmyadmin {
               root /usr/share/;
               index index.php index.html index.htm;
               location ~ ^/phpmyadmin/(.+\.php)$ {
                       try_files $uri =404;
                       root /usr/share/;
                       fastcgi_pass 127.0.0.1:9000;
                       fastcgi_index index.php;
                       fastcgi_param SCRIPT_FILENAME $request_filename;
                       include /etc/nginx/fastcgi_params;
               }
               location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                       root /usr/share/;
               }
        }
        location /phpMyAdmin {
               rewrite ^/* /phpmyadmin last;
        }

}

You're missing the entry for static.the-sps.org. Either add it in the current servername directive (therefore serving the contents of /srv/www/the-sps.net/publichtml) or make an entire new server {} entry just for static content.

````
server {
servername static.the-sps.net; accesslog /srv/www/the-sps.net/logs/access.log;
errorlog /srv/www/the-sps.net/logs/error.log; root /srv/www/the-sps.net/publichtml;

location / {
return 403;
}

location ~* ^.+.(jpg|jpeg|gif|png|ico|swf|css|js)$ {
access_log off;
expires 45d;
}
}

and you should use

server {
server_name the-sps.net;
rewrite ^ http://www.the-sps.net/$request_uri? permanent;
}

````
instead of that if{$host…}.

So I should add something like this to my config?

server {
    listen              80 default_server;
    server_name         c.the-sps.org;
    access_log          /srv/www/the-sps.org/logs/access.log;
    error_log           /srv/www/the-sps.org/logs/error.log;
    root                /srv/www/the-sps.org/public_html;

I'm not sure what you intend for the c.the-sps.org domain. If you use c.the-sps.org for static assets then you can use the same config as above for static.the-sps.org. Or just add the domain to the servername line if you are using both or multiple static domains. (e.g. servername static.mydomain.com img.mydomain.com a.mydomain.com b.mydomain.com c.mydomain.com;)

BUT, I can't imagine that you want default_server on the listen line.

The defaultserver is the server configuration it goes to if the incoming request HOST doesn't match any of your servername values. For example, if they went to the IP address directly, or if some malicious person crafted a request with your IP but with some special HOST.

I generally specify every domain in the server_name lines and then send anything non-matching into the ether with this:

# Close connection for any host not explicitly named
server {
  listen 80 default_server;
  return 444;
}

Although if you had 100 completely different hosts and wanted to use one catch-all config for all of them instead of specifying them each by name, you might use default_server.

Ahhh I see now.

I'm using c the same as static above, I''ll just use the conf above though. Awesome!

Brianmercer I love you!!!!!!!!!

Xx

Here's my config now, is this looking better?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct