简体   繁体   English

如果访问者的地址是某个IP,NginX会在index.html上重定向

[英]NginX redirect on index.html if visitor's Address is a certain IP

My problem is that I'm doing some side work besides regular job. 我的问题是除了常规工作外,我还在做一些辅助工作。

I would like to avoid someone to visit my page from work. 我想避免有人下班访问我的页面。 The site loads index.html as default, but I have an index.php on the site what I would like see, so can't just redirect everyone from " workip " to some othe site... 该网站默认加载index.html,但是我希望看到的是网站上的index.php,所以不能仅仅将每个人从“ workip ”重定向到其他网站...

So what I would like is: If source is " work IP " and goes to " http://www.mydomain.com/index.html " be redirected to www.google.com but not on other pages. 所以我想要的是:如果源是“ 工作IP ”并转到“ http://www.mydomain.com/index.html ”,则重定向到www.google.com,但不在其他页面上。

Any idea how to get this done in NginX? 知道如何在NginX中完成此操作吗?

I've just got it figured out... 我刚想通了...

location /index.html {
 if ($remote_addr = 1.2.3.4 ) {
  rewrite ^ http://www.google.com/;
 }
}

Use an NGINX location block: 使用NGINX位置块:

location /index.html {
   if ($remote_addr = 1.2.3.4 ) {
      rewrite ^ http://www.google.com/;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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