nginx烂笔头

  1. nginx可以转发websocket请求,具体配置如下

    1
    new Websocket('ws://127.0.0.1/ws/123456')
    1
    2
    3
    4
    5
    6
    location /ws/ {
    proxy_pass http://backend:8887;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    }

    这么配置会将请求转发至ws://backend:8887/ws/123456

  2. 如若转发时不想带上前端的前缀,可以这么配置

    1
    axios.get('http://ip/prod-api/get')
    1
    2
    3
    location /prod-api/{
    proxy_pass http://backend:8887/;
    }

    这么配置会将请求转发至http://backend:8887/get