业务需求
业务和开发同事需要我这边做一条规则,所有访问 ip 为非上海、广州 office 外网 ip,url 为http://test.com/fuck/index.html 的请求都跳转到 http://test.com/index.html 。然后所有在上海和广州 office 的外网 IP 访问 http://test.com/fuck/index.html 依然还是 http://test.com/fuck/index.html。这样就可以在生产上做隔离,不影响其他用户的服务。
注:因为目前生产上的 Nginx 没有做 lua 支持,所以就无法通过使用 lua 来实现该需求,也没有安装 geoip ,所以也无法用模块来支持,只能原生的。
原始的 nginx 配置
upstream service_test {
server 127.0.0.1:8080;
}
server
{
listen 80;
server_name test.com;
index index.html index.php;
root /tmp/test.com;
error_page 404 http://test.com/404.html;
error_page 502 http://test.com/502.html;
error_page 500 http://test.com/500.html;
location ~* \.(gif|jpg|jpeg|png|css|js|ico|txt|svg|woff|ttf|eot)$
{
rewrite ^(.*)$ /static$1 break;
root /tmp/test.com; #
expires 1d;
}