Nginx: Proxy pass / proxy redirect to shiny web applications

≡放荡痞女 提交于 2021-01-27 13:32:08

问题


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.

Setup:

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

  • both docker container are members of an docker network

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

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

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

  • 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)

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

Nginx.conf

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;
}

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 ?

Thanks for your help, Tobi


回答1:


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.



来源:https://stackoverflow.com/questions/51269677/nginx-proxy-pass-proxy-redirect-to-shiny-web-applications

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!