Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Black nginx magic
PostPosted: Thu Dec 01, 2011 6:13 pm 
Offline
Senior Newbie

Joined: Sun Nov 27, 2011 4:54 pm
Posts: 15
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


Top
   
 Post subject:
PostPosted: Thu Dec 01, 2011 6:29 pm 
Offline
Senior Newbie
User avatar

Joined: Mon Aug 24, 2009 10:37 am
Posts: 18
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.


Top
   
 Post subject: Re: Black nginx magic
PostPosted: Thu Dec 01, 2011 6:32 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
ChemicalKicks wrote:
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

Code:
server_name    _;


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

Mean-meanwhile, care to post your nginx config?


Top
   
 Post subject:
PostPosted: Thu Dec 01, 2011 6:41 pm 
Offline
Senior Newbie

Joined: Sun Nov 27, 2011 4:54 pm
Posts: 15
Daevien wrote:
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


Top
   
 Post subject: Re: Black nginx magic
PostPosted: Thu Dec 01, 2011 6:43 pm 
Offline
Senior Newbie

Joined: Sun Nov 27, 2011 4:54 pm
Posts: 15
Azathoth wrote:
ChemicalKicks wrote:
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

Code:
server_name    _;


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

Mean-meanwhile, care to post your nginx config?


Code:
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;
        }

}
[/code]


Top
   
 Post subject: Re: Black nginx magic
PostPosted: Thu Dec 01, 2011 8:56 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
You're missing the entry for static.the-sps.org. Either add it in the current server_name directive (therefore serving the contents of /srv/www/the-sps.net/public_html) or make an entire new server {} entry just for static content.


Top
   
 Post subject:
PostPosted: Thu Dec 01, 2011 11:05 pm 
Offline
Senior Member

Joined: Sun Feb 21, 2010 5:12 pm
Posts: 64
Code:
server {
  server_name static.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 / {
    return 403;
  }

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

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

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


Top
   
 Post subject:
PostPosted: Wed Dec 28, 2011 1:13 pm 
Offline
Senior Newbie

Joined: Sun Nov 27, 2011 4:54 pm
Posts: 15
So I should add something like this to my config?

Code:
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;
   


Top
   
 Post subject:
PostPosted: Wed Dec 28, 2011 1:34 pm 
Offline
Senior Member

Joined: Sun Feb 21, 2010 5:12 pm
Posts: 64
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 server_name line if you are using both or multiple static domains. (e.g. server_name 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 default_server is the server configuration it goes to if the incoming request HOST doesn't match any of your server_name 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:

Code:
# 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.


Top
   
 Post subject:
PostPosted: Wed Dec 28, 2011 2:36 pm 
Offline
Senior Newbie

Joined: Sun Nov 27, 2011 4:54 pm
Posts: 15
Ahhh I see now.

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


Top
   
 Post subject:
PostPosted: Wed Dec 28, 2011 2:44 pm 
Offline
Senior Newbie

Joined: Sun Nov 27, 2011 4:54 pm
Posts: 15
Brianmercer I love you!!!!!!!!!

Xx

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group