nginx做代理服务器转发http请求和websocket请求

2017-08-31  本文已影响0人  打工是不可能打工的1

假如我们不想把真实的请求地址暴露给外部我们可以把请求转发给其他服务器,使用nginx做代理服务器是非常方便点的


server {

listen80;

server_name  localhost;

#项目根目录

charset UTF-8;

access_log   logs/access.log  main;

error_log logs/error.log;

location / {

proxy_pass http://localhost:88;

}
}

要做websocket的转发只要在在location中添加多两条规则就可以了

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

贴上代码

server {
        listen       80;
        server_name  localhost;
        #项目根目录
        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了

上一篇下一篇

猜你喜欢

热点阅读