配置nginx并重启生效
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:3000/;
}
获取客户端ip
async asyncData({ app, params, req, error, redirect }) {
// get user ip
let clientIp = req.headers['x-forwarded-for'] || req.headers['x-real-ip']
}
这个方法,可以扩展到所有的后端服务
参考