zubinmehta
zubinmehta

Reputation: 4533

nginx sub-domain mapping

I want to open xyz.abc.com in the browser but internally(using python-django), I want to map this to abc.com/xyz The following nginx conf code works, but I don't want to redirect the user to this new url (abc.com/xyz)

server {
    listen   80;
    server_name xyz.abc.com;

    location / {
        rewrite ^ http://abc.com/xyz;
        break;
}

I have tried a lot of things including using proxy_pass but it's not working. How can I solve this?

Thanks.

Upvotes: 0

Views: 628

Answers (1)

sergzach
sergzach

Reputation: 6764

You can convert any 3rd level domain to 2nd level:

server {
    listen   80;
    server_name ~^(?<domain>.*)\.abc\.com;

    location / {
        proxy_pass http://abc.com/$domain$request_uri;
        break;
}

In your case try the next:

server {
    listen   80;
    server_name xyz.abc.com;

    location / {
        proxy_pass http://abc.com/xyz$request_uri;
        break;
}

About the request_uri: http://wiki.nginx.org/HttpCoreModule

Upvotes: 1

Related Questions