How to deploy with port redirect (proxy) with nginx?
Hello! I have a working containerized web solution (JS), which I wanted to test if I could deploy on HF spaces.To run the container locally, you can simply do:docker run -p 3000:80 ohif4hfProblem is that HF spaces does not seem to support settingapp_port=3000:80in the README, only ints, e.g.,app_port=3000. In that case I do not get the appropriate port redirect (proxy). It deploys just fine locally. What is the easiest way to get this working? Quick note, I’m not an experiences web developer.The project is located at (although it is not working currently and is prone to changes):huggingface.coandreped/ohif4hf at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.
2023-09-18T18:59:29Z
hi@andreped,You have to change the default port on the Ngnix conf file, since we don’t allow biding ports lower than#1024,See this example here using Nginx as a reverse proxy for two apps running on the same Space. I’m using port 4444 with Ngnix.huggingface.conginx.conf · radames/nginx-gradio-reverse-proxy at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.
2023-09-18T19:24:11Z
Aaah, that explains some things. Cheers! :]Let me give it a go and rewrite my Dockerfile and nginx config based on the reverse proxy example. Will give you an update on how it goes.
2023-09-18T19:47:42Z
Here is another example. Note that we have to install nginx and add specific permission, since we can’t run it as root,huggingface.coDockerfile · radames/ComfyUI-data-index at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.huggingface.conginx.conf · radames/ComfyUI-data-index at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.
2023-09-18T21:33:30Z
Hmm, I tried rewriting the Dockerfile and config, but when running the final container, the final website does not show.I believe it might have to do with how the original project setup their nginx config and that they used thenginxinc/nginx-unprivileged:1.25-alpineimage, which was different from the one you used (seeherefor original Dockerfile).Swapping this with your solution did not even work locally, so I guess something is not compatible. Maybe the config is just wrong (seeherefor original config).Basically, whatever I do, I am unable to access the website with only a single port ID. It does not redirect as it should. So I cannot deploy it on HF spaces. Even though the original3000:80worked fine.
2023-09-19T04:37:13Z
Hi@andreped,I had a quick look at the OHIF documentation and it appears that you can have a PORT environment variable to configure a different Nginx port. So I created a simple Dockerfile and set the PORT environment variable to 7860, which is the default port on Spaces, and it works.FROM ohif/app:latestHowever, I noticed that you would need a custom Nginx configuration file to properly configure cross-origin isolation. So, I modified the Dockerfile from the original repository appropriately and also added this extra configuration to our Spaces README. md to enablecustom headers.Feel free to duplicate.Dockerfile:Dockerfile · radames/OHIF-Medical-Imaging-Viewer at mainDemo:Ohif - a Hugging Face Space by radames
2023-09-19T06:40:58Z
Just tried incorporating your ideas and it works wonders! Thank you so much! This was a nice thing to wake up to :]I never would have thought about modifying theapp-config.js. I also noticed that you no longer set theapp_portin the README. But how does this affect local deployment? I just tried running the built container locally, but it does not show inlocalhost. Is there a default port I’m not setting or similar?Screenshot 2023-09-19 at 08.34.411920×1040 80.9 KB
2023-09-19T17:00:48Z
Great!Note on my Dockerfile I’ve skipped theentrypoint.shand I’m copying a custom a nginx.conf to the imageDockerfile · radames/OHIF-Medical-Imaging-Viewer at mainandnginx.confAnd if you run locally usedocker run -ti -p 7860:7860 tag-name
2024-03-02T04:10:40Z
Hi@radamesDo you mind checking out my space and helping me with the same issue as this thread.AAMI - a Hugging Face Space by BtebbuttI am using a port above 1024 but it’s not working. Thanks so much
2024-03-02T20:23:29Z
hi@Btebbutt,Could you please make your Space public?
2024-03-03T03:38:38Z
Thanks for the reply@radames. The space is now public , and I can see my front end , but it’s not communicating with the backend. I think it’s either to do with how I have set up the nginx config, or how I have set up the environment variables. Your help would be highly highly appreciated.huggingface.coAAMI - a Hugging Face Space by BtebbuttDiscover amazing ML apps made by the community
2024-03-03T22:37:41Z
I think think the issue is with the nginx, maybe try thisBtebbutt/AAMI · try this
2024-03-04T01:28:04Z
Hi@radames. I merged the changes, but the backend still has problems connecting to the front end. Thanks again
2024-03-04T01:52:29Z
I’ve forked your Space, with these nginx config changes, I got it to respond onhttps://radames-aami.hf.space/custom-auth. You endpoint here also workshttps://btebbutt-aami.hf.space/custom-authare you pointing your front-end to the right route?
2024-03-04T10:15:43Z
ended up getting it working. Thanks for helping out@radames. Had to handle WS in the nginx conf file.
2024-03-04T22:16:33Z
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.