假如我們不想把真實(shí)的請(qǐng)求地址暴露給外部我們可以把請(qǐng)求轉(zhuǎn)發(fā)給其他服務(wù)器潜腻,使用nginx做代理服務(wù)器是非常方便點(diǎn)的
server {
listen80;
server_name localhost;
#項(xiàng)目根目錄
charset UTF-8;
access_log logs/access.log main;
error_log logs/error.log;
location / {
proxy_pass http://localhost:88;
}
}
要做websocket的轉(zhuǎn)發(fā)只要在在location中添加多兩條規(guī)則就可以了
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
貼上代碼
server {
listen 80;
server_name localhost;
#項(xiàng)目根目錄
charset UTF-8;
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:88;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
}
只要就成功把localhost:80成功代理到localhost:88了