AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1089250
Accepted
Toorero
Toorero
Asked: 2022-01-07 16:55:43 +0800 CST2022-01-07 16:55:43 +0800 CST 2022-01-07 16:55:43 +0800 CST

用于 SSH 隧道的 Apache 反向代理

  • 772

我想为在本地网络中运行的 Home-Assistant(hass) 实例设置一个 Apache 反向代理。

我将本地 hass 实例的流量通过隧道传输到远程服务器ssh -N [email protected] -R 8123:localhost:8123。

现在我尝试在 Apache 中设置一个普通的反向代理:

<VirtualHost *:443>
    ServerName hass.example.com

    SSLEngine On

    # If you manage SSL certificates by yourself, these paths will differ.
    SSLCertificateFile fullchain.pem
    SSLCertificateKeyFile privkey.pem

    SSLProxyEngine on
    SSLProxyProtocol +TLSv1.2 +TLSv1.3
    SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyVia On
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
    
            
    # Proxy all traffic to hass
    ProxyPass / http://localhost:8123/ nocanon
    ProxyPassReverse / http://localhost/
    ErrorLog ${APACHE_LOG_DIR}/hass.example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/hass.example.com-access.log combined
    <IfModule security2_module>
        SecRuleEngine off
    </IfModule>
</VirtualHost>

<VirtualHost *:80>
    ServerName hass.example.com

    Redirect permanent / "https://hass.example.com"

    ErrorLog ${APACHE_LOG_DIR}/hass.example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/hass.example.com-access.log combined
</VirtualHost>

可悲的是,如果我尝试打开hass.example.com,浏览器会以400: Bad Request.

ssh ssh-tunnel apache-2.4 apache2
  • 1 1 个回答
  • 555 Views

1 个回答

  • Voted
  1. Best Answer
    Toorero
    2022-02-20T09:48:03+08:002022-02-20T09:48:03+08:00

    这一切都归结为Home-Assistant 阻止反向代理尝试,并且您还必须代理 websocket 请求。

    调整后的 hass-config ( config/configuration.yaml):

    http:
      use_x_forwarded_for: true
      trusted_proxies:
      - ::1
      - 127.0.0.1
      ip_ban_enabled: true
      login_attempts_threshold: 5
    

    阿帕奇配置:

    <VirtualHost *:443>
        ServerName hass.example.com
    
        SSLEngine On
    
        # If you manage SSL certificates by yourself, these paths will differ.
        SSLCertificateFile fullchain.pem
        SSLCertificateKeyFile privkey.pem
    
        SSLProxyEngine on
        SSLProxyProtocol +TLSv1.2 +TLSv1.3
        SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
    
        ProxyPreserveHost On
        ProxyRequests Off
        ProxyVia On
        RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
        
                
        # Proxy all traffic to hass
        RewriteEngine On
        RewriteCond %{HTTP:Upgrade} =websocket
        RewriteRule /(.*) ws://localhost:8123/$1 [P]
        RewriteCond %{HTTP:Upgrade} !=websocket
        RewriteRule /(.*) http://localhost:8123/$1 [P]
        ProxyPassReverse / http://localhost:8123
    
    
        ErrorLog ${APACHE_LOG_DIR}/hass.example.com-error.log
        CustomLog ${APACHE_LOG_DIR}/hass.example.com-access.log combined
        <IfModule security2_module>
            SecRuleEngine off
        </IfModule>
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName hass.example.com
    
        Redirect permanent / "https://hass.example.com"
    
        ErrorLog ${APACHE_LOG_DIR}/hass.example.com-error.log
        CustomLog ${APACHE_LOG_DIR}/hass.example.com-access.log combined
    </VirtualHost>
    
    • 0

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve