nginx使用笔记

272 阅读1分钟

一、调用接口302使用nginx配置更改location

例如访问 http://localhost:8080/api/a 接口session失效会导致接口302 header.Location = www.baidu.com
实际上访问 http://192.168.0.0:8081/api/a 接口session失效会导致接口302 header.Location = localhost:8080/login

location /api/ {
    header_filter_by_lua_block {
        local url = ngx.header.Location
        if url then
          ngx.header.Location = 'localhost:8080/login'
        end
    }
    proxy_pass http://192.168.0.0:8081
}

二、调用接口302使用nginx配置更改host

例如访问 http://localhost:8080/api/a 接口session失效会导致接口302 header.Location = www.baidu.com/aaa
实际上访问 http://192.168.0.0:8081/api/a 接口session失效会导致接口302 header.Location = localhost:8080/aaa

location /api/ {
    proxy_set_header Host localhost:8080
    proxy_pass http://192.168.0.0:8081
}