需求:先後端在同一個服務器,端口不一樣html
後端端口8082,前端端口8080,須要將前端的/box請求轉到後端的8082端口,參考配置以下前端
server {
listen 8080;
server_name www.box.com;apache
location /box/ {
proxy_pass http://localhost:8082/;後端
#若是服務器須要獲取真實ip,須要配置如下服務器
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}spa
location / {
root box;
index index.html;
}
}code
若是服務端是servlet,而且須要獲取真實ip,須要在server.xml的host節點下面加入以下:server
<Valve className="org.apache.catalina.valves.RemoteIpValve" />