nginx server redirect
Edho P Arief
edhoprima at gmail.com
Sun Jun 21 18:32:11 MSD 2009
On Sun, Jun 21, 2009 at 8:21 PM, Kevin
Castiglione<kevincastiglione at gmail.com> wrote:
> On Sat, Jun 20, 2009 at 10:30 PM, Edho P Arief <edhoprima at gmail.com> wrote:
>>
>> On Sun, Jun 21, 2009 at 12:19 PM, Edho P Arief<edhoprima at gmail.com> wrote:
>> >
>> > here it is
>> > server {
>> > listen 80;
>> > server_name ~(.*)\.([^\.]*)\.([^\.]*)$;
>> > set $domain $2.$3;
>> > rewrite ^.* http://$domain$request_uri permanent;
>> > }
>> >
>> make sure that you have the server_name set on nginx or it'll redirect to
>> .
>
> can you tell how i set server_name on nginx for this to work?
>
create separate server block for each domain name
server {
listen 80;
server_name abcd.com;
...
}
which will be used when nginx detects the domain as abcd.com
without this block, the redirection will go like this:
NNN.abcd.com => abcd.com => . (dot)
with this it'll access correct site instead (stop at abcd.com)
>
>>
>> this will catch all anydomain.tld
>> server {
>> listen 80;
>> server_name ~[^\.]*\.[^\.]*;
>> return 403;
>> }
>
> i dont understand what you mean by catch all anydomain.tld?
> can you pl. explain this?
> thanks a lot!
>
>
catch whatever that matches such pattern (asd.com, fghqwe.net,
zxclkj.org, asdf.ghjk, etc) and return 403 (in this example)
without this block, the previous server_name
(~(.*)\.([^\.]*)\.([^\.]*)$;) will catch this pattern and redirect to
'.'
--
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the nginx
mailing list