环境:
客户机–>VUE服务器—>nginx—>php swoole后台服务
nginx配置,/etc/nginx/conf.d/xxx.conf
location /
{
# root /www/mhj;
proxy_pass http://127.0.0.1:8326;
proxy_http_version 1.1;
proxy_read_timeout 360s;
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_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 REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
add_header Cache-Control no-cache;
expires 12h;
}
在php代码中,通过$this->request->server(‘HTTP_ORIGIN’)可以获取VUE服务器的地址
本文介绍了在一个客户机-VUE服务器-nginx-phpswoole后台服务环境中,如何配置Nginx以代理请求到phpswoole服务。配置包括设置proxy_pass、缓存控制、头部信息等,确保了WebSocket升级和请求转发的正确性。同时,通过PHP代码中的HTTP_ORIGIN获取VUE服务器地址,展示了前后端通信的关键步骤。
1387

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



