Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “如何运行”;“日食”;NGINX反向代理背后?_Java_Eclipse_Nginx_Url Rewriting_Reverse Proxy - Fatal编程技术网

Java “如何运行”;“日食”;NGINX反向代理背后?

Java “如何运行”;“日食”;NGINX反向代理背后?,java,eclipse,nginx,url-rewriting,reverse-proxy,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] Rewri

我在服务器上安装了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个webapps:

ide
dashboard 
swagger
如果EclipseChe支持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)中添加了重写规则 谢谢你的帮助。

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

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;

即使使用WebSocket支持,您也会遇到反向代理的问题(后者仅在您希望通过SSH直接连接到运行时时时才有用)

目前,我看到的唯一实用和安全的解决方案是制作一个VPN


不过,这是对Che的改进。

这对我在Apache上使用基于Apache http代理的转发很有效。 然后我就可以在那里使用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>

服务器管理员webmaster@localhost
服务器名che.xyz.com
ServerAlias che.xyz.com
DocumentRoot/var/www/html
...
...
ProxyPass/http://localhost:8080/
ProxyPassReverse/http://localhost:8080/

谢谢,我已将这些行添加到配置文件中,但仍然不走运。