Skip to content

Commit

Permalink
fix: nginx 获取并向 web 传递用户真实 ip
Browse files Browse the repository at this point in the history
  • Loading branch information
xjq committed Nov 2, 2022
1 parent 03ad9e6 commit e75eb36
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ server {
location /{
limit_req zone=limitRate burst=15 nodelay;
limit_conn addr 10;
proxy_set_header X-Real-IP $remote_addr;
proxy_ssl_server_name on;
proxy_pass http://127.0.0.1:39005;
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/middleware/decorator/Ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function Ip() {
const req = action.request;
const headers = action.request.header;
let ip =
headers['x-forwarded-for'] ||
headers['X-Real-IP'] ||
headers['x-forwarded-for'] ||
req.ip ||
req.connection?.remoteAddress || // 判断 connection 的远程 IP
req.socket?.remoteAddress || // 判断后端的 socket 的 IP
Expand Down

0 comments on commit e75eb36

Please sign in to comment.