在宝塔设置反向代理后直接访问报错:400: Bad Request 找错误中一些巧合 添加反代 目标URL:http://[域名]:8123 发送域名:域名 添加如下代码:
- 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 [url]https://hass.xxx.cn:8123;[/url]
- 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 [url]https://hass.xxx.cn:8123;[/url]
- 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 [url]https://hass.xxx.cn:8123;[/url]
- 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 [url]https://hass.xxx.cn:8123;[/url]
- 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/
复制代码Home-Assistant方面的设置获取反向代理源IP
- 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上面最下面那几个ip就是白名单列表,可以把公网IP和本地IP也写上去。
复制代码
|