Answer the question
In order to leave comments, you need to log in
How to correctly transfer real ip from nginx to go-server?
Dobryi day
The request to understanding to prompt on two questions.
1) how to correctly transfer the real ip of users from nginx to the server with a websocket? tried these instructions:
https://dev.to/hackersandslackers/deploy-a-golang-...
https://serveradmin.ru/nginx-proxy_pass/#Peredaca_...
location = /game {
proxy_pass http://localhost:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
user.conn.RemoteAddr().String()
https://pkg.go.dev/net?tab=doc#Addr
127.0.0.1:52696
[::1]:42120
Answer the question
In order to leave comments, you need to log in
user.conn.RemoteAddr().String()
gives the nginx IP with which conn
. To transfer the real ip of users, you need to attach it to the request header. Something like nginx config
location / {
...
proxy_set_header X-Real-IP $remote_addr;
...
*http.Request.Header.Get("X-Real-IP")
[::1]:42120
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question