简体   繁体   中英

nginx redirect mask

I'm new to nginx and am trying to figure out an issue with redirection. I'm trying to redirect a website from a host running a web application to another domain. That part I've done but I'm looking to mask it. When it redirects, I don't want the user to know they've gone to another domain.

I've substituted the domain names for privacy of my client. But, they are on a Linode at test.com that's running a web application that's at sub.test.com. All I want is for any user visiting test.com to be redirected to a temporary site hosted on other.com but without exposing the domain.

Previously, someone had shown me how to do it but it was a long time ago and I no longer have the information to reference. Can someone help me out? I don't want to expose the domain of the testing environment.

server {
     listen       80;
     server_name  www.test.com test.com www.test.net test.net;

     rewrite      ^ http://other.com/sub redirect;

     location / {
         root     /srv/http/www.test.com;
         index    index.html;
     }
}

You can't do that with redirect , cause redirect is actually like telling the browser where to fetch page from, so you can't obscure the real location. I guess what you need is proxying , eg a client requests some document from your server (test.com), then your server fetches the document from some other server (other.com) and returns that document to a client as if it was generated on test.com - it that case a client won't be able to determine where actually the document is originating from.

This can be done with:

server_name test.com;
location / {
    proxy_pass http://other.com;
}

如果您希望重定向不更改用户可见的域名,则需要通过如下更改更改将其从301更改为302:

rewrite ^ http://other.com/sub redirect;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM