panchicore
panchicore

Reputation: 11932

how to configure nginx to serve specific django url path with another domain

I have configured nginx + uwsgi to serve foo.com, but foo.com/bar/ I want to serve it like bar.com

example: foo.com/bar/test/ = bar.com/test/

also I want to make bar.com robots not allowed.

any suggestion?

Upvotes: 2

Views: 874

Answers (2)

Dayo
Dayo

Reputation: 12775

server {
    listen   80;
    server_name foo.com;
    root   /full/server/path/to/foo/folder;
    index index.html index.php;
    # This redirects anyone that directly types "foo.com/bar/xyz to bar.com/xyz"
    if ($request_uri ~ ^/bar(.*)$) {
        return 301 http://bar.com$1;
        # Alternative for old nginx versions
        # rewrite ^ http://bar.com$1 redirect;
    }

    # foo.com location blocks go below
    ...
}

server {
    listen   80;
    server_name bar.com;
    root /full/server/path/to/foo/bar/folder;
    index index.html index.php;

    # bar.com location blocks go below
    ...
}

Upvotes: 0

Burhan Khalid
Burhan Khalid

Reputation: 174624

Assuming you have foo.com configured as:

location / {
 # your normal stuff
}

Something like this should work:

location / {
   rewrite  ^/bar/(.*)$  bar.com/$1? break;
}

For blocking robots, see this nginx forum entry.

Upvotes: 1

Related Questions