Black nginx magic
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
Here's the black magic part, if you visit
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
@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;
}
}
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…}.
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;
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.
I'm using c the same as static above, I''ll just use the conf above though. Awesome!
Xx
Here's my config now, is this looking better?