简体   繁体   English

子目录中的Vue主机开发服务器web socket

[英]Vue host development server web socket in subdirectory

I'm trying to host a Vue development server (including the web socket) in a subdirectory of my domain using nginx, but with my current setup it looks like the vue server is responding to requests instead of the webpack development server.我正在尝试使用 nginx 在我的域的子目录中托管一个 Vue 开发服务器(包括 Web 套接字),但在我当前的设置中,看起来 vue 服务器正在响应请求而不是 webpack 开发服务器。

To be clear, I want my app to be hosted on https://xxx.yyy/zzz/ , I want assets, etc hosted in https://xxx.yyy/zzz/path/to/asset , and I want the webpack dev server hosted in https://xxx.yyy/zzz/sockjs-node/info?t=... .明确地说,我希望我的应用程序托管在https://xxx.yyy/zzz/ ,我希望资产等托管在https://xxx.yyy/zzz/path/to/asset ,我希望webpack 开发服务器托管在https://xxx.yyy/zzz/sockjs-node/info?t=... I'm pretty sure this should be possible without special casing the nginx setup because it works without the subdirectory.我很确定这应该是可能的,而无需对 nginx 设置进行特殊设置,因为它可以在没有子目录的情况下工作。

Here's my setup so far:到目前为止,这是我的设置:

nginx nginx

server {
    # server name, ssl, etc

    location /test/ {
        proxy_pass http://localhost:8080;
    }
}

Create the project创建项目

$ vue create -d hello-world

vue.config.js vue.config.js

module.exports = {
    publicPath: '/test/',
    devServer: {
        public: "0.0.0.0/test",
        disableHostCheck: true,
    }
}

Then running然后运行

$ npm run serve

The client makes requests to all the right places, but客户端向所有正确的地方发出请求,但是

$ curl https://xxx.yyy/test/sockjs-node/info

gives back index.html , whereas返回index.html ,而

$ curl localhost:8080/sockjs-node/info

gives back the expected websocket info.返回预期的 websocket 信息。 I have also tried changing the nginx setup to proxy_pass http://localhost:8080/;我也尝试将 nginx 设置更改为proxy_pass http://localhost:8080/; , but that causes index.html to not render when I go to https://xxx.yyy/test/ because it's expecting a path and isn't being forwarded one. ,但是当我转到https://xxx.yyy/test/时,这会导致index.html无法呈现,因为它需要一条路径并且没有被转发。 When I also change publicPath to / , I can't get the client to look in the right subdirectory for assets.当我还将publicPath更改为/ ,我无法让客户端在正确的子目录中查找资产。

Is there a correct way to do this?有没有正确的方法来做到这一点?

It is possible to set the socket path using:可以使用以下方法设置套接字路径:

module.exports = {
    //...
        devServer: {
        sockPath: 'path/to/socket',
    }
};

In this case:在这种情况下:

sockPath: '/test/sockjs-node', 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM