如何在NGINX反向代理后面运行“Eclipse Che”?

时间:2016-01-28 09:18:53

标签: java eclipse nginx url-rewriting reverse-proxy

我已安装在Eclipse Che服务器上,当我在本地使用它时,它在我的机器上运行完美 localhost:8080

我想在互联网上提供NGINX前端反向代理。这是一个想法:

example.com/che / ---> NGINX反向代理 ---> 服务器:8080 /

我尝试了很多不同的NGINX配置......但没有成功。 有关信息,Eclipse Che嵌入了一些带有一些重写规则的Tomcat实例:

RewriteRule ^/api/ext/(.*)$ /ide/ext/$1 [L]
RewriteRule ^/api/(.*)$ /ide/api/$1 [L]
RewriteRule ^/$ /dashboard [R]

Tomcat服务器上部署了3个webapp:

ide
dashboard 
swagger

如果Eclipse Che落后于NGINX,上述重写规则是无用的,可以由NGINX直接完成(这就是我所做的)

我想在我的NGINX配置中有一个单独的块(如果可能)这是我到目前为止尝试做的,但它没有完全正常工作,Eclipse Che没有完全加载(我的猜测是WebSockets没有被代理) ,我想念一些事情)基本上,我试图“代理”不同的webapps,但这可能不是最好的选择。

location /dashboard {
 proxy_pass http://localhost:8080/dashboard;
 proxy_redirect off;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /ide {
 proxy_pass http://localhost:8080/ide;
 proxy_redirect off;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api {
 rewrite ^/api/ext/(.*)$ /ide/ext/$1 redirect;
 rewrite ^/api/(.*)$ /ide/api/$1 redirect;
}

您可以注意到我在NGINX“api”位置添加了重写规则,而不是在Tomcat配置中添加了重写规则(ROOT webapp) 谢谢你的帮助。

3 个答案:

答案 0 :(得分:1)

仅供参考http://nginx.org/en/docs/http/websocket.html

您必须添加特定于websocket连接升级的conf:

map $http_upgrade $connection_upgrade {
            default upgrade;
            ''      close;
        }

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

答案 1 :(得分:0)

即使使用WebSocket支持,您也有问题要反向代理randomly assigned ports in range 32768‒65535 and the optional SSH port(后者仅在您希望通过SSH直接连接到运行时才有用)。

目前我看到的唯一实用且安全的解决方案是建立VPN。

然而{改变了on the roadmap

答案 2 :(得分:0)

这适用于Apache,使用基于apache http proxy的转发。 然后我可以去http://che.xyz.com/并从那里使用che。 哦,我确实必须将che.xyz.com映射到我服务器的IP地址。

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName che.xyz.com
    ServerAlias che.xyz.com
    DocumentRoot /var/www/html
    ...
    ...
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>