If nuxt is running behind a proxy such as nginx, then you can get the client's IP address in asyncData by reading x-real-ip or x-forwarded-for. Be aware that x-forwarded-for can contain comma separated IPs if a call has passed through additional proxys (if there is multiple entries, then the client is the first one).
Make sure to set up the headers in your nginx site configuration
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Then you can read the headers in asyncData:
async asyncData(context) {
if (process.server) {
const req = context.req
const headers = (req && req.headers) ? Object.assign({}, req.headers) : {}
const xForwardedFor = headers['x-forwarded-for']
const xRealIp = headers['x-real-ip']
console.log(xForwardedFor)
console.log(xRealIp)
}
}