简体   繁体   English

Apache 反向代理背后的 Apache Zeppelin

[英]Apache Zeppelin behind Apache reverse proxy

I'm running my Apache Zeppelin instance behind an Apache Webserver, where the webserver only serves as a reserve proxy.我在 Apache Web 服务器后面运行我的 Apache Zeppelin 实例,其中 Web 服务器仅用作备用代理。

If I'm browsing to the reverse-proxy site https://my-domain.com/zeppelin/ I'm getting a website with assets and buttons and everything, but the websocket of Zeppelin won't connect.如果我正在浏览反向代理站点https://my-domain.com/zeppelin/我将获得一个包含资产和按钮以及所有内容的网站,但 Zeppelin 的 websocket 无法连接。 The Browser-Dev-Tools are saying 405 HTTP method GET is not supported by this URL for the URL https://my-domain.com/zeppelin/ws . Browser-Dev-Tools 说405 HTTP method GET is not supported by this URL用于 URL https://my-domain.com/zeppelin/ws

If I'm going direct on the Zeppelin-Website (fe http://priv.my-domain.com/zeppelin ) everything works fine.如果我直接访问 Zeppelin 网站(fe http://priv.my-domain.com/zeppelin ),一切正常。 So it seems like it's not a bug in the Zeppelin-Code but a problem in the reverse-proxy-config.因此,这似乎不是 Zeppelin-Code 中的错误,而是反向代理配置中的问题。

My Apache reverse-proxy config looks like:我的 Apache 反向代理配置如下所示:

<VirtualHost *:443>
    ServerName my-domain.com
    # don't loose time with IP address lookups
    HostnameLookups Off
    ProxyRequests Off
    ProxyPreserveHost Off
    SSLEngine On
    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    ...
    ssl cert stuff
    ...
    <Location /zeppelin/ws>

        ProxyPass ws://priv.my-domain.com:8080/zeppelin/ws
        ProxyPassReverse ws://priv.my-domain.com:8080/zeppelin/ws

        Order deny,allow
        Deny from all

        Allow from <my-ip>

    </Location>

    <Location /zeppelin/>

        ProxyPass http://priv.my-domain.com:8080/zeppelin/
        ProxyPassReverse http://priv.my-domain.com:8080/zeppelin/

        Order deny,allow
        Deny from all

        Allow from <my-ip>

    </Location>
    <Proxy *>
        AddDefaultCharset Off
        Order deny,allow
        Allow from all
    </Proxy>
</VirtualHost>

It makes no difference if I remove the first ws-location from the config.如果我从配置中删除第一个 ws-location 没有区别。 Have you any idea?你有什么想法吗?

EDIT FOR SOLUTION: After the below answer I modified my conf-file and it's working now!编辑解决方案:在下面的答案之后,我修改了我的 conf 文件,它现在可以工作了! Thank you really much!非常感谢!

My working conf:我的工作配置:

<VirtualHost *:443>
    ServerName my-domain.com
    # don't loose time with IP address lookups
    HostnameLookups Off
    ProxyRequests Off
    ProxyPreserveHost Off
    SSLEngine On
    SSLProxyEngine On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    ...
    ssl cert stuff
    ...
    <Location /zeppelin/>

        ProxyPass http://priv.my-domain.com:8080/zeppelin/
        ProxyPassReverse http://priv.my-domain.com:8080/zeppelin/

        Order deny,allow
        Deny from all

        Allow from <my-ip>

    </Location>
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =WebSocket [NC,NV]
    RewriteRule ^/(.*) ws://priv.my-domain.com:8080/$1 [P]
    <Proxy *>
        AddDefaultCharset Off
        Order deny,allow
        Allow from all
    </Proxy>
</VirtualHost>

This is the conf I am using which has some specifies not necessarily applicable for your needs :这是我正在使用的 conf,它有一些不一定适用于您的需求的指定:
- service discovery in front of a mesos cluster - 在 mesos 集群前发现服务
- one instance per user and routing the user based on the credentials - 每个用户一个实例并根据凭据路由用户

<VirtualHost *:3128>
    <Location "/"> 
      AuthUserFile  /.............../users
      AuthName "xxxxxxxxxxxxx" 
      AuthGroupFile /dev/null 
      AuthType Basic 
      Require valid-user
    </Location> 
    ServerName xxxxxxxxxxxxxxxxxxxxxxxxxxx
    # SSLEngine on
    # SSLCertificateFile "/.............../xxxxx.crt"
    # SSLCertificateKeyFile "/.............../xxxxx.key"

  #RewriteRules for datalab with user
  RewriteCond %{HTTP:Upgrade} =WebSocket [NC,NV]
  RewriteCond %{LA-U:REMOTE_USER} (aaaa)
  RewriteRule ^/(.*) ws://azerty01:31321/$1 [P]
  RewriteCond %{LA-U:REMOTE_USER} (aaaa)
  RewriteRule ^/(.*) http://azerty01:31321/$1 [P,QSA,L]
  ProxyPassReverse / http://azerty01:31321

  #RewriteRules for datalab with user
  RewriteCond %{HTTP:Upgrade} =WebSocket [NC,NV]
  RewriteCond %{LA-U:REMOTE_USER} (bbbb)
  RewriteRule ^/(.*) ws://azerty02:31901/$1 [P]
  RewriteCond %{LA-U:REMOTE_USER} (bbbb)
  RewriteRule ^/(.*) http://azerty02:31901/$1 [P,QSA,L]
  ProxyPassReverse / http://azerty02:31901

</VirtualHost>

Here is an Includes file that I created when I wanted to reverse proxy Zeppelin server.这是我想反向代理 Zeppelin 服务器时创建的 Includes 文件。 You could more or less cut and paste it into a vhosts conf file if preferred.如果愿意,您可以或多或少地将其剪切并粘贴到 vhosts conf 文件中。

#
# Apache Reverse Proxy settings for Zeppelin server.
# note:
#  Change ZEPPELING_IP_OR_HOST and ZEPPELIN_PORT as appropriate.
#
# FreeBSD put into /usr/local/etc/apache24/Includes directory,
# Linux may vary.

# This is for your-host.your-domain.com/zeppelin 
# if you want zeppelin.your-host.your-domain.com
# Put this into a vhosts file.

RequestHeader set X_FORWARDED_PROTO 'https'
ProxyPreserveHost On
RequestHeader set X-Forwarded-Port "443"
ProxyRequests     Off
ProxyVia Off
AllowEncodedSlashes NoDecode


<Location /zeppelin/ws>
    ProxyPass  ws://ZEPPELIN_IP_OR_HOST:ZEPPELIN_PORT/zeppelin/ws 
    ProxyPassReverse ws://ZEPPELIN_IP_OR_HOST:ZEPPELIN_PORT/zeppenlin/ws
</Location>

ProxyPass        /zeppelin     http://ZEPPELIN_IP_OR_HOST:ZEPPELIN_PORT/zeppelin 
ProxyPassReverse /zeppelin     http://ZEPPELIN_IP_OR_HOST:ZEPPELIN_PORT/zeppelin

I found that the order of the location directives matters.我发现位置指令的顺序很重要。 If you define the zeppelin first then zeppelin/ws as shown below, then everything works.如果您首先定义 zeppelin,然后 zeppelin/ws 如下所示,那么一切正常。 However, the reversed order doesn't work.但是,相反的顺序不起作用。

   <Location /zeppelin/>
        ProxyPass http://priv.my-domain.com:8080/zeppelin/
        ProxyPassReverse http://priv.my-domain.com:8080/zeppelin/
    </Location>
    <Location /zeppelin/ws>
        ProxyPass ws://priv.my-domain.com:8080/zeppelin/ws
        ProxyPassReverse ws://priv.my-domain.com:8080/zeppelin/ws
    </Location>

Just to add to this, I was able to use Apache2 with the config below to reroute to my zeppelin instance.只是为了补充一点,我能够使用带有以下配置的 Apache2 重新路由到我的 zeppelin 实例。 The important piece is the websocket connection.重要的部分是 websocket 连接。

Make sure you add确保你添加

sudo a2enmod proxy_wstunnel

to the mods.到模组。 I then ran the following:然后我运行了以下命令:

sudo a2dissite 000-default
sudo nano /etc/apache2/sites-available/proxy-host.conf
    # Insert the following into the proxy-host.conf file
    <VirtualHost *:80>
      ServerName '<Zeppelin Public IP>:8080'
      RewriteEngine On
      RewriteCond %{HTTP:Upgrade} =websocket [NC]
      RewriteRule /(.*)           ws://<Zeppelin Public IP>:8080/$1 [P,L]
      RewriteCond %{HTTP:Upgrade} !=websocket [NC]
     RewriteRule /(.*)           http://<Zeppelin Public IP>:8080/$1 [P,L]
     ProxyPassReverse / http://<Zeppelin Public IP>:8080/
    </VirtualHost>
    # / text insert
sudo a2ensite proxy-host
sudo nano /etc/apache2/ports.conf
   #Add this to the ports.conf file and cntrl+X to save & exit  
   Listen 8080
sudo /etc/init.d/apache2 restart

Then when you go to http:// reverseproxypublicIP / it'll reroute to your Zeppelin instance.然后,当您访问 http:// reverseproxypublicIP / 时,它会重新路由到您的 Zeppelin 实例。 Hope this helps someone!希望这可以帮助某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM