一、Nginx配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream ws {
server localhost:8081;
server localhost:8082;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
二、webpack配置
const proxys = [
{
option: {
target: 'http://localhost:8081/',
changeOrigin: true,
ws: true,
secure: false
}
}
]
本文详细介绍了Nginx的反向代理配置方法,包括HTTP升级为WebSocket的支持,以及如何使用Webpack进行代理配置,实现本地开发环境的跨域请求处理。


被折叠的 条评论
为什么被折叠?



