原创

nginx反向代理http和websocket

upstream blog-admin {
    server localhost:8006;
}

server {
    listen 80;
    server_name oneblog.94rg.com;

    # 允许跨域
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
    if ($request_method = 'OPTIONS') {
        return 204;
    }
    location / {
            proxy_pass http://blog-admin/;
            proxy_set_header Host $proxy_host;
        }
    location /websocket {
            proxy_pass http://blog-admin/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
正文到此结束