需要:一臺服務器,安裝了nginx:
打開要進行反向代理的項目server:加入反向代理代碼;nginx.conf
location /abcd { proxy_http_version 1.1; proxy_pass http://0.0.0.0:9503;#這個地方是你需要進行實際訪問的網址地址; proxy_redirect off; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Port $remote_port; proxy_set_header sec-websocket-Protocol mqtt; #如果需要進行訪問權限驗證的話需要加上 proxy_connect_timeout 60s; proxy_read_timeout 120s; proxy_send_timeout 120s; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
正常訪問如:http://www.baidu.com:9503這個端口才能訪問到你的頁面;
現在你可以訪問:http://www.baidu.com/abcd訪問到的和http://www.baidu.com:9503就是相同頁面了;進行了重定向處理