ai-dock / comfyui

ComfyUI docker images for use in GPU cloud and local environments. Includes AI-Dock base for authentication and improved user experience.
Other
530 stars 188 forks source link

Webui force redirects from domain name to public IP #60

Closed theman23290 closed 5 months ago

theman23290 commented 6 months ago

I am trying to tie this service to a public domain so I can access it anywhere. When I have it set to a domain and navigate to it, the service will redirect me to my public IP which will reject the connection. Is there a way to set the hostname so that it will go to example.domain.com instead of redirecting me to my public IP? Further is there a way that the services like ComfyUI, Jupiter, ect... to be set to their own sub domains so I don't have to worry about the specific ports and the main navigation page sees those links? If need be I can hardcode the main page once logged in if you could please tell me where that main page script is located so I can append the links.

theman23290 commented 6 months ago

I was able to figure out the hostname thing. For future reference make sure that "DIRECT_ADDRESS_GET_WAN" is false.

Now a new problem arises. With the hostname, the website wants the connection to go through the original port. For instance if I call the service from the internet, it redirects to https://comfyui.example.com:1111/login when it should be https://comfyui.example.com/login. For some odd reason it is injecting the port number into the web address. Is there a setting which will tell it to operate without the port number in the address? The main drawback to this being each service would need to have its own subdomain, but that is a small price to pay.

robballantyne commented 6 months ago

You can either use cloudflare named tunnels (easiest) or point your domain to a reverse proxy in front of this container.

theman23290 commented 6 months ago

The reverse proxy method is exactly what I am trying to do. But for some odd reason when I navigate to https://comfyui.example.com/ it will then redirect me to https://comfyui.example.com:1111/ which is incorrect. I have tried to mess around with every docker compose flags as I can as well as every nginx command to no avail. I am suspecting something besides the reverse proxy and the compose file is adding the "1111" port at the end. I am really at a loss and beyond my knowledge as to why it is redirecting me with a port number on a https connection.Is there something I can change to make it not include the port in the connection address?

robballantyne commented 6 months ago

The redirect happens because there is no Auth header in the initial request. All unauthenticated requests are passed to serviceportal at 1111 and then onto 1111/login

Depending how your networking is configured you may be able to set WEB_ENABLE_AUTH=false and handle authentication separately.

There is a very specific usecase for these containers where the current method is necessary and works well but I'll need to look at how to modify behaviours for alternative uses.

theman23290 commented 6 months ago

I did end up figuring out how to forward the websites to a public domain. I used custom locations and separate domains to make the services go with /login and /ai-dock in the custom locations. A bummer though is I have to copy the url from the services page, type in the specific url pointing to comfyui, then append the url to have that key on the end. I would like to have a setting in the services page or docker compose file in the future to set custom urls to the services so it automatically adds the key saving time. I know it is out of scope now but it would be a nice feature to have. I really use this service for the authentication measures it provides. I am closing this issue as my issue is resolved but I do hope in the future being able to set custom urls to the services specifically and having the program autofill all the /api-dock/pre-auth... at the end.

robballantyne commented 6 months ago

@theman23290 I think it would be a good addition. I'll try and get around to adding this as a feature.

It will probably be as simple as modifying the logic for getting the direct address.

It might look like: New variable [SERVICE]_URL, if set, taking priority over [SERVICE]_PORT_HOST.

I appreciate you raising the issue and I'm going to reopen so it doesn't get forgotten.

robballantyne commented 6 months ago

This is done as I described above. You can specify the following:

SERVICEPORTAL_URL=https://portal.example.com
COMFYUI_URL=https://comfyui.example.com
JUPYTER_URL=https://jupyter.example.com
SYNCTHING_URL=https://syncthing.example.com

Login will be at https://portal.example.com/login

I have used subdomains as an example but you can use whatever suits your situation.

This change only affects how the service portal lists links and redirects to /login - Services will continue to be available at IP:port

theman23290 commented 6 months ago

I can see the change in the compose file but the DIRECT_ADDRESS is overriding the new arguments. I have tried setting the DIRECT_ADDRESS as 127.0.0.1, setting it as its private IP, and leaving the field blank. I have tried removing the argument and set the new arguments above DIRECT_ADDRESS line to no avail. If I set the "127.0.0.1" or private IP in the field, the links will result in those IPs with the port numbers after. If I don't set the value or remove the argument all together, the link will be set to http://localhost:port... Is there a new format I need to follow so the docker compose follows the new arguments?

robballantyne commented 6 months ago

Which image tag are you using? Have you pulled the updated version?

DIRECT_ADDRESS is not used for a service port when there is a [SERVICE]_URL present. See https://github.com/ai-dock/base-image/blob/main/build/COPY_ROOT/opt/ai-dock/bin/direct-url.sh

theman23290 commented 6 months ago

I have tried the main branch and that base-image repo and they both have the same issue. I am modifying the arguments in the environment section of the compose file. I have tried:

Both of those formats is not working in the compose file. DIRECT_ADDRESS or if it is missing, is still overriding it with either http://127.0.0.1:8188 or http://localhost:8188. Is there a different place I need to put those arguments?

theman23290 commented 5 months ago

I was able to figure it out. I needed to pull the main branch of this project and download the direct-url.sh file from the above link to ./build/COPY_ROOT/opt/ai-dock/bin/direct-url.sh in the comfyui folder. Once that file is in the main branch's git clone I can append the arguments in the docker-compose file with the format of "COMFYUI_URL=${COMFYUI_URL:-https://comfyui.example.com}". It works like a dream, I can now click on the links in the Services Portal and it loads the links with ease. Thanks for making this new feature happen!