来源:群晖自带nginx反代hass方法 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz! (hassbian.com)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;#PROXY-START/
location ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
proxy_pass https://hass.xxx.cn:8123;
proxy_set_header Host hass.xxx.cn;
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;
expires 12h;
}
location /
{
proxy_pass https://hass.xxx.cn:8123;
proxy_set_header Host hass.xxx.cn;
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;
}
#PROXY-END/#PROXY-START/
location ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
proxy_pass https://hass.xxx.cn:8123;
proxy_set_header Host hass.xxx.cn;
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;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
expires 12h;
}
location /
{
proxy_pass https://hass.xxx.cn:8123;
proxy_set_header Host hass.xxx.cn;
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;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
add_header Cache-Control no-cache;
}
#PROXY-END/配置>日志,查看日志。Received X-Forwarded-For header from an untrusted proxy 172.17.0.1A request from a reverse proxy was received from 172.17.0.1,but your HTTP integration is not set-up for reverse proxies172.17.0.1.crt、.key证书文件拷贝到config目录configuration.yaml,添加如下配置(视情况修改),然后重启服务:http:
base_url: [域名]
ssl_certificate: [.crt文件]
ssl_key: [.key文件]
use_x_forwarded_for: true
trusted_proxies:
- 1.14.147.22
- 172.17.0.1
- 127.0.0.1
- ::1