Nginx:代理传递/代理重定向到闪亮的 Web 应用程序 [英] Nginx: Proxy pass / proxy redirect to shiny web applications

查看:45
本文介绍了Nginx:代理传递/代理重定向到闪亮的 Web 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试更新我们的内部服务器基础设施,并通过 Nginx 服务器代理对我们的 R 闪亮网络服务器的所有访问.我能够从闪亮的服务器获得响应,但我无法通过 Nginx 服务器获得 css/js 等相关文件.

We are trying to update our internal server infrastructure and to proxy all accesses to our R shiny webservers through an Nginx server. Im able to get a response from the shiny server but Im not able to get related files like css/js through the Nginx server.

  • 2 个 docker 容器(1 个用于托管 nginx,1 个运行 R 用于闪亮的应用程序)

  • 2 docker container (1 for hosting nginx, 1 running R for a shiny application)

两个 docker 容器都是 docker 网络的成员

both docker container are members of an docker network

shiny server 监听 7676 端口(内部 ip-adress 172.18.0.3)

shiny server listens to port 7676 (internal ip-adress 172.18.0.3)

nginx 服务器托管了一些带有 iFrame 的静态 html 文件(旧的,无法摆脱),这些文件应该显示闪亮服务器的内容

nginx server is hosting few static html files with iFrames (legacy, cant get ride off), which should show content of the shiny server

访问 nginx-server/QueryLandscape.html 加载带有 iFrame <iframe src="ilandscape"></iframe>

accessing nginx-server/QueryLandscape.html loads the page with the iFrame <iframe src="ilandscape"></iframe>

iFrame 工作:它加载 R-shiny 应用程序的静态部分,但它不加载相关的 JS/CSS/....(例如 http://nginx-server:8001/ilandscape/shared/shiny.css)

iFrame works: it loads the static part of R-shiny application, but it doesnt load the related JS/CSS/....(e.g. http://nginx-server:8001/ilandscape/shared/shiny.css)

在 nginx-docker 容器中,我可以访问这个 css 文件 wget 172.18.0.3:7676/shared/shiny.css

within the nginx-docker container i can access this css file wget 172.18.0.3:7676/shared/shiny.css

location /ilandscape/ {
    proxy_pass http://172.18.0.3:7676/;
    #proxy_redirect http://172.18.0.3:7676/ $scheme://$host/;

    # websocket headers
    proxy_set_header Upgrade $http_upgrade;

    proxy_http_version 1.1;
    proxy_read_timeout 20d;
    proxy_set_header Host $host;
}

我的 nginx conf 中缺少什么来代理/重定向 http://nginx-server:8001/ilandscape/shared/shiny.css -->172.18.0.3:7676/shared/shiny.css ?

What am I missing in my nginx conf to proxy/redirect http://nginx-server:8001/ilandscape/shared/shiny.css --> 172.18.0.3:7676/shared/shiny.css ?

感谢您的帮助,托比

推荐答案

看起来作为浏览器的 iframe 正在接收主机名而不是资源的完整路径.您能否设置以下 ReverseProxy 标头并试一试:

Looks like the iframes acting as a browser are receiving the hostname instead of the full path to the resources. Can you set up the following ReverseProxy headers and give it a go:

proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

基本上你现在有一个代理,我们也想要一个反向代理.让我知道这是否有效.

Basically you have a proxy at the moment, and we want a reverse proxy too. Let me know if this works.

这篇关于Nginx:代理传递/代理重定向到闪亮的 Web 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆