Nginx - map usage

Redirect depending on the domain

How to write a configuration file for nginx to redirect, depending on the domain to any section of the site.

We have a domain, motto.com, kids.com, meet.com and figvam.com. Is the main domain forum.com, which we want to redirect them (depending on the domain will be a different forum). The most correct version of this:

http {

    map $http_host  $forum_id{
        hostnames;

        default          "";

        .motto.com        "11";

        .kids.com         "12";

        .meet.com         "13";
        .figvam.com       "13";
    }

    server {
        listen 80 default;

        rewrite ^ http://forum.com/?f=$forum_id;
    }

    server {
        listen 80;

        server_name  forum.com www.forum.com;

        location / {
            proxy_pass http://localhost:80/;
        }
    }
}

Reduce Ngix config for virtualhost

We have a few ip addresses, including the client with ssl (domain super.com) which has a private ip address (1.2.3.4). For nginx is apache. The task given nginx static files.

Nginx configuration looks like this:

http {

    map $http_host $user {
        hostnames;
        default "igor;

        include users.list;
    }

    map $http_host $domain {
        hostnames;
        default "hosting.com";

        include domains.list;
    }

    server {
        listen 80 default;

        server_name  hosting.com;

        include vhost.conf;

    }

    server {
        listen 1.2.3.4:443;

        server_name  super.com;

        ssl  on;

        ssl_certificate      super.com.cert.pem;
        ssl_certificate_key  super.com.key.pem;

        ssl_session_timeout  5m;

        ssl_protocols  SSLv3 TLSv1;
        ssl_ciphers    ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:-SSLv2:+SSLv3:+EXP;

        ssl_prefer_server_ciphers   on;

        include vhost.conf;
    }
}

vhost.conf:

location ~* ^/.+\.(ico|gif|png|jpg|avi|js|css)$ {
    root  /home/$user/domains/$domain/htdocs;
}

location / {
    root  /home/$user/domains/$domain/htdocs;

    proxy_redirect       off;
    proxy_set_header     Host $new_host;
    proxy_set_header     X-Real-IP $remote_addr;
    proxy_set_header     X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass           http://127.0.0.1:80;
}

location ~ /\.ht {
    return 403;
}

users.list:

.motto.com    dave;
.auto.com     nick;
.porno.com    jack;
.super.com    charley;

domains.list:

.mottor.com   auto.com;
.auto.com     auto.com;
.porno.com    porno.com;
.super.com    super.com;

What makes this scheme? Adding a new domain (for nginx) is to create a user (if necessary) and the creation of his domain, and append the information in two files and users.list domains.list, instead of creating a very large number of configs. And all clients for apache to be virtual, all the ssl configured at the level of nginx.

 
nginx/map.txt · Last modified: 2010/02/11 09:17 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Please visit Automatic Backlinks to start earning free backlinks Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki