hyperf2.1框架的web及websocket服务在nginx上反向代理的配置
hyperf框架项目在nginx上的web站点反向代理配置
线上体验地址:https://blog.zongscan.com/
主要的是网站及websocket服务聊天
nginx上配置文件 目录:/usr/local/nginx/conf/vhost/xx.conf文件
#-----------------s
upstream web {
server 192.168.1.98:9501;
}
upstream websocket {
server 192.168.1.98:9502;
}
server
{
listen 80;
listen 443 ssl http2;
server_name blog.zongscan.com;
ssl_certificate /usr/local/nginx/conf/cert/5444141_blog.zongscan.com.pem;
ssl_certificate_key /usr/local/nginx/conf/cert/5444141_blog.zongscan.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
#80重定向443
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#指向文件
location = /favicon.ico{ root /opt/bg;}
location = /robots.txt{ root /opt/bg;}
location = /ads.txt{ root /opt/bg;}
#WebSocket服务
location /ws {
# WebSocket Header
proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection "Upgrade";
# 将客户端的 Host 和 IP 信息一并转发到对应节点
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# 客户端与服务端无交互 60s 后自动断开连接,请根据实际业务场景设置
proxy_read_timeout 60s ;
# 执行代理访问真实服务器
proxy_pass http://websocket;
}
#web
location / {
# 将客户端的 Host 和 IP 信息一并转发到对应节点
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 执行代理访问真实服务器
proxy_pass http://web;
}
access_log /home/wwwlogs/hyperf.log main_log;
}
#------------------------------end
完
相关文章