david
September 1, 2008, 2:10am
1
Hi,
Following this example from the docs:
#rewrites Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan. => Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan.
if ($host ~* www.(.)) {
set $host_without_www $1;
rewrite ^(. )$ http://$host_without_www$1 permanent; # $1 contains
‘/foo’, not
‘www.mydomain.com/foo ’
}
Would the opposite of that be:
#rewrites Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan. => Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan.
if ($host ~* !^(.).mydomain.nl$) {
rewrite ^(. )$ Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan. permanent;
}
Does that make sense ?
Is $host_without_www a reserved variable ? and is the inverse
$host_with_www ?
Thanks
david
September 1, 2008, 7:14am
2
On Sun, Aug 31, 2008 at 11:59:39PM +0000, David wrote:
#rewrites Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan. => Domeinnaam Mydomain.nl overnemen? Koop nu en start met je plan.
if ($host ~* !^(.).mydomain.nl$) {
rewrite ^(. )$ http://www.mydomain.nl/$1 permanent;
}
Does that make sense ?
Is $host_without_www a reserved variable ? and is the inverse $host_with_www ?
No, $host_without_www is not reserved name.
Try the following:
if ($host ~* !^(.*).mydomain.nl$) {
if ($host !~* ^(.*).mydomain.nl$) {
BTW, it’s better to use something like this instead of “if”:
server {
server_name www.maydomain.nl;
…
}
server {
server_name maydomain.nl;
rewrite ^(.*)$ http://www.mydomain.nl/$1 permanent;
}
david
September 1, 2008, 9:00am
3
yeah, i took your suggestion and this is what i’ve been using, with
the added addition of redirecting and keeping the URI
server {
listen 80;
server_name www.michaelshadle.com;
rewrite ^/(.*) http://michaelshadle.com/$1 permanent;
}
server {
listen 80;
server_name michaelshadle.com;
index index.php;
root /htdocs/michaelshadle.com/;
... etc ...
}
david
September 1, 2008, 9:38am
4
On 9/1/08, Igor S. [email protected] wrote:
Just for info, here is some configuration that returns 404 for any invalid
hostname if you do not want to associate your site with these names:
server {
listen 80 default;
server_name _;
return 404;
}
this would probably work to log any unknown host headers/missing host
headers, right?
server {
listen 80 default;
server_name _;
return 404;
access_log /var/log/nginx/unmapped.log;
root /htdocs/unmapped/;
}
another question:
is there any reason to require the ending slash “/” ?
root /htdocs/unmapped/;
as opposed to:
root /htdocs/unmapped;
i used to think it was required but it seems to work properly now
without the slash too.
david
September 1, 2008, 9:09am
5
On Sun, Aug 31, 2008 at 11:52:07PM -0700, mike wrote:
listen 80;
server_name michaelshadle.com;
index index.php;
root /htdocs/michaelshadle.com/;
... etc ...
}
Just for info, here is some configuration that returns 404 for any
invalid
hostname if you do not want to associate your site with these names:
server {
listen 80 default;
server_name _;
return 404;
}
server {
listen 80;
server_name www.michaelshadle.com
67.228.73.162 # your IP address
""; # request without host
header
#redirect stuff;
}
server {
listen 80;
server_name michaelshadle.com;
#main site
}
david
September 1, 2008, 9:42am
6
On Mon, Sep 01, 2008 at 12:29:44AM -0700, mike wrote:
this would probably work to log any unknown host headers/missing host
headers, right?
server {
listen 80 default;
server_name _;
return 404;
access_log /var/log/nginx/unmapped.log;
root /htdocs/unmapped/;
}
Yes.
another question:
is there any reason to require the ending slash “/” ?
root /htdocs/unmapped/;
as opposed to:
root /htdocs/unmapped;
i used to think it was required but it seems to work properly now
without the slash too.
There is no difference for “root” directive. Actually, nginx deletes
trailing slash from “root” directive because $request_file_name is
$document_root$uri", and $uri has slash as first character.
But the trailing slash is important for “alias” directive, because
“alias” literally replaces location part of URI:
location /dir/ {
alias /path/to/;
}
/dir/file > /path/to/file
david
September 1, 2008, 9:54am
7
On Mon, Sep 01, 2008 at 12:43:58AM -0700, mike wrote:
alias /path/to/;
}
/dir/file > /path/to/file
Gotcha. Thanks.
Just to make clean:
location /dir/ {
alias /path/to;
}
/dir/file > /path/tofile
or
location /dir {
alias /path/to/;
}
/dir/file > /path/to//file
david
September 1, 2008, 9:52am
8
On 9/1/08, Igor S. [email protected] wrote:
/dir/file > /path/to/file
Gotcha. Thanks.
david
September 1, 2008, 2:15pm
9
Thank you Igor, that is a great solution.
"
BTW, it’s better to use something like this instead of “if”:
server {
server_name www.maydomain.nl;
…
}
server {
server_name maydomain.nl;
rewrite ^(.*)$ http://www.mydomain.nl/$1 permanent;
}
"