Nginx前後端分離傳遞客戶端IP

Nginx前後端分離傳遞客戶端IP

前後端分離,採用nginx作爲靜態服務器,並通過反向代理的方式實現接口跨域,導致後端獲取的請求都是前端IP。

	server {
        listen       80;
        server_name  localhost;
        
        proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Real-Port $remote_port;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        location / {
            proxy_pass http://myTomcatServer;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

proxy_set_header Host $host; # 可能導致502

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章