HASS设置Nginx代理-博客园
HASS设置Nginx代理
遇到问题
设置反代完成后,在浏览器中输入 https://ha.xxx.ml
。但是登陆完成后,却一直连接不上
查阅了一圈资料,发现主要原因是因为 在配置代理的时候需要配置好websocket的相关参数。
proxy_set_headerUpgrade $http_upgrade;
proxy_set_headerConnection "upgrade";
proxy_read_timeout 86400;
总配置文件
server
{
listen 80;
listen 443 ssl http2;
server_name ha.xxx.ml;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/ha.xxx.ml;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate /www/server/panel/vhost/cert/ha.xxx.ml/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/ha.xxx.ml/privkey.pem;
# ..............省略部分配置
#清理缓存规则
location ~ /purge(/.*) {
proxy_cache_purge cache_one $host$1$is_args$args;
}
#引用反向代理规则,注释后配置的反向代理将无效
include /www/server/panel/vhost/nginx/proxy/ha.xxx.ml/*.conf;
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/ha.xxx.ml.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
access_log /www/wwwlogs/ha.xxx.ml.log;
error_log /www/wwwlogs/ha.xxx.ml.error.log;
}
反向代理配置文件
#PROXY-START/
location ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
proxy_pass http://172.27.53.161:8123;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
expires 12h;
}
location /
{
proxy_pass http://172.27.53.161:8123;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
add_header Cache-Control no-cache;
}
#PROXY-END/