我试图在基于云的开发环境中使用Vite dev服务器,在这个环境中,我可以服务并连接到端口,但需要通过代理路径访问它们。
我将不访问http://localhost:3000/index.html,而是访问https://my.cool.example.com/proxy/3000/index.html。在幕后,云服务通过转换URL和代理连接:因此,为了使之更好,看起来我只是在请求/index.html。
...But --我在vite.config.js中尝试过的各种吐露--还没有使它正常工作:
如/proxy/3000/"
base:“服务器配置了一个this answer的公共基URL,其他未成功的server.base、proxy、publicPath和类似的实验
我如何告诉Vite,客户端和资产应该在请求上设置路径前缀,但是服务器可以从根服务器服务?
发布于 2022-05-09 19:08:27
解决此问题的解决方案是在filename.conf文件中的nginx中使用许多反向代理,如果您需要设置类似的内容
location /admin {
include /etc/nginx/includes/proxy.conf;
proxy_pass https://your-service:8081;
}
location ^~ /@vite {
include /etc/nginx/includes/proxy.conf;
proxy_pass https://your-service:8081;
}
location /__vite_ping {
include /etc/nginx/includes/proxy.conf;
proxy_pass https://your-service:8081;
}
location /src {
include /etc/nginx/includes/proxy.conf;
proxy_pass https://your-service:8081;
}
location /node_modules {
include /etc/nginx/includes/proxy.conf;
proxy_pass https://your-service:8081;
}proxy.conf文件以这种方式查看。
xy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_intercept_errors on; 在您的vite.config中,您必须这样做。
server: {
https: true,
host: "0.0.0.0",
port: 8081,
secure: false,
strictPort: true,
hmr: {
port: 8081,
host: "localhost",
},
},重要的想法是对hrm值进行覆盖,并且端口必须与您在码头上公开的端口相同。
docker-compose.yml服务vaues
ports:
- '8081:8081'在index.html上,必须更新脚本src path。
来自< script type=“模块”“src="/src/main.js”>
到< script type=“模块”src="https://localhost:8081/src/main.js“>
发布于 2022-04-20 00:00:27
我遇到了完全相同的问题,文档说在https://github.com/http-party/node-http-proxy#options上有更多的代理选项。
https://stackoverflow.com/questions/71686045
复制相似问题