sourcebot-dev / sourcebot

Blazingly fast code search 🏎️ Deployed as a single Docker image 📦 Search million+ lines of code in your GitHub, GitLab, and Gitea repositories 🪄 MIT licensed ✅
https://sourcebot.dev
MIT License
1.17k stars 37 forks source link

Reverse proxy support #61

Closed deavmi closed 1 week ago

deavmi commented 3 weeks ago

Hi, I am currently trying to run this with an NGINX reverse proxy in front of it, but the URL paths are not playing nicely.

Any advice?

brendan-kellam commented 3 weeks ago

Hey thanks for raising a issue - do you mind pasting your nginx config so I can try to replicate?

I actually haven't run it in front of a reverse proxy so it's a good question :)

deavmi commented 3 weeks ago

Let me get that for you

On 08 November 2024 09:10:02 SAST, Brendan Kellam @.***> wrote:

Hey thanks for raising a issue - do you mind pasting your nginx config so I can try to replicate?

I actually haven't run it in front of a reverse proxy so it's a good question :)

-- Reply to this email directly or view it on GitHub: https://github.com/sourcebot-dev/sourcebot/issues/61#issuecomment-2463924965 You are receiving this because you authored the thread.

Message ID: @.***>


Tristan B. Velloza Kildaire

Web: https://deavmi.assigned.network BNET IRC: deavmi Email: @.***

deavmi commented 3 weeks ago

Here we go:

         # sourcebot
                location ^~ /bot/
        {
                proxy_pass http://sourcebot:3000/;
                proxy_http_version 1.1;
                proxy_set_header Connection "upgrade";
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header X-Forwarded-Proto $scheme;

                # by default nginx times out connections in one minute
                proxy_read_timeout 1d;
        }
brendan-kellam commented 3 weeks ago

thanks - I'm heading to bed now but I will try this out in the morning. Could you also send over any logs / further describe what the issue is?

deavmi commented 2 weeks ago

Sure. Will do when at home

On 08 November 2024 09:53:15 SAST, Brendan Kellam @.***> wrote:

thanks - I'm heading to bed now but I will try this out in the morning. Could you also send over any logs / further describe what the issue is?

-- Reply to this email directly or view it on GitHub: https://github.com/sourcebot-dev/sourcebot/issues/61#issuecomment-2463983695 You are receiving this because you authored the thread.

Message ID: @.***>


Tristan B. Velloza Kildaire

Web: https://deavmi.assigned.network BNET IRC: deavmi Email: @.***

deavmi commented 2 weeks ago

Hi, so I don't really have much logs but I can show you what it renders like:

image

deavmi commented 2 weeks ago

If I open the Network log, in chromiu, it seems all requests are being made at the root / and *not** /bot/, that is the problem

deavmi commented 2 weeks ago

Any updates on this?

brendan-kellam commented 2 weeks ago

Sorry I haven't gotten a chance to look into this yet - I will take a look today and get back to you

deavmi commented 2 weeks ago

Thanks man, appreciate it a lot :-)

On 14 November 2024 20:09:35 SAST, Brendan Kellam @.***> wrote:

Sorry I haven't gotten a chance to look into this yet - I will take a look today and get back to you

-- Reply to this email directly or view it on GitHub: https://github.com/sourcebot-dev/sourcebot/issues/61#issuecomment-2477095827 You are receiving this because you authored the thread.

Message ID: @.***>


Tristan B. Velloza Kildaire

Web: https://deavmi.assigned.network BNET IRC: deavmi Email: @.***

brendan-kellam commented 2 weeks ago

Heya - I was able to repro the issue. As you mentioned, all CSS, JS, and image requests are 404'ing since they are referencing the root / and not the redirected /bot path:

image

I looked into it and Next.js has a basePath config variable that I tested and seemed to work. One fix here may be to make that configurable and expose a BASE_PATH env var that gets passed tobasePath. I can look into that tomorrow.

In the meantime, would it be possible to serve it directly at the root /? Or possibly, use a subdomain?

deavmi commented 2 weeks ago

I like the BASE_PATH envvar approach.

Currently it won't be possible for me to serve it at the root as I have other stuff on /

On 15 November 2024 09:55:32 SAST, Brendan Kellam @.***> wrote:

Heya - I was able to repro the issue. As you mentioned, all CSS, JS, and image requests are 404'ing since they are referencing the root / and not the redirected /bot path:

image

I looked into it and Next.js has a basePath config variable that I tested and seemed to work. One fix here may be to make that configurable and expose a BASE_PATH env var that gets passed tobasePath. I can look into that tomorrow.

In the meantime, would it be possible to serve it directly at the root /? Or possibly, use a subdomain?

-- Reply to this email directly or view it on GitHub: https://github.com/sourcebot-dev/sourcebot/issues/61#issuecomment-2478166278 You are receiving this because you authored the thread.

Message ID: @.***>


Tristan B. Velloza Kildaire

Web: https://deavmi.assigned.network BNET IRC: deavmi Email: @.***

brendan-kellam commented 1 week ago

Hey @deavmi - I just opened a PR with this change. I have validated it locally with my nginx conf file and all seems to work. If you have a sec, would you mind checking out my branch, building a image, and testing with your config?

deavmi commented 1 week ago

Hi, I will give this a try sometime in tonight or early tomorrow morning. Thanks!

On 16 November 2024 08:50:41 SAST, Brendan Kellam @.***> wrote:

Hey @deavmi - I just opened a PR with this change. I have validated it locally with my nginx conf file and all seems to work. If you have a sec, would you mind checking out my branch, building a image, and testing with your config?

-- Reply to this email directly or view it on GitHub: https://github.com/sourcebot-dev/sourcebot/issues/61#issuecomment-2480454087 You are receiving this because you were mentioned.

Message ID: @.***>


Tristan B. Velloza Kildaire

Web: https://deavmi.assigned.network BNET IRC: deavmi Email: @.***

deavmi commented 1 week ago

Hey @deavmi - I just opened a PR with this change. I have validated it locally with my nginx conf file and all seems to work. If you have a sec, would you mind checking out my branch, building a image, and testing with your config?

Want me to build from source the Dockerimage?

deavmi commented 1 week ago

Hey @deavmi - I just opened a PR with this change. I have validated it locally with my nginx conf file and all seems to work. If you have a sec, would you mind checking out my branch, building a image, and testing with your config?

Want me to build from source the Dockerimage?

Had difficulties doing this, maybe a ghcr release (alpha) for this branch would do?

brendan-kellam commented 1 week ago

No worries - I will just merge the PR now to main and that will kickoff a ghcr release to main. If there are issues, we can open up another PR after

deavmi commented 1 week ago

No worries - I will just merge the PR now to main and that will kickoff a ghcr release to main. If there are issues, we can open up another PR after

Cool cool, I will be up tonight and can test in the next hours :)

deavmi commented 1 week ago

Waiting on the artm64 image to be built... QEMU speedz

deavmi commented 1 week ago

BASE_PATH

Should I set BASE_PATH to https://example.com/bot?

brendan-kellam commented 1 week ago

Set DOMAIN_SUB_PATH to /bot

deavmi commented 1 week ago

Set DOMAIN_SUB_PATH to /bot

Sure, will do

deavmi commented 1 week ago

Set DOMAIN_SUB_PATH to /bot

Weird, doesn't seem to be working my side

brendan-kellam commented 1 week ago

Are images not loading? Or is there something else that's not working?

For reference, this is my nginx.conf I was using that worked:


worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        location ^~ /bot/ {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Connection "upgrade";
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;

            # by default nginx times out connections in one minute
            proxy_read_timeout 1d;
        }
    }

    include servers/*;
}
deavmi commented 1 week ago

Yeah same problem as before.

Let me compare my nginx config with mine and test again shortly.

On 18 November 2024 23:13:57 SAST, Brendan Kellam @.***> wrote:

Are images not loading? Or is there something else that's not working?

For reference, this is my nginx.conf I was using that worked:


worker_processes  1;

events {
   worker_connections  1024;
}

http {
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

   server {
       listen       8080;
       server_name  localhost;

       location ^~ /bot/ {
           proxy_pass http://localhost:3000;
           proxy_http_version 1.1;
           proxy_set_header Connection "upgrade";
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_set_header X-Forwarded-Proto $scheme;

           # by default nginx times out connections in one minute
           proxy_read_timeout 1d;
       }
   }

   include servers/*;
}

-- Reply to this email directly or view it on GitHub: https://github.com/sourcebot-dev/sourcebot/issues/61#issuecomment-2484142682 You are receiving this because you were mentioned.

Message ID: @.***>


Tristan B. Velloza Kildaire

Web: https://deavmi.assigned.network BNET IRC: deavmi Email: @.***

deavmi commented 1 week ago

Are images not loading? Or is there something else that's not working?

For reference, this is my nginx.conf I was using that worked:


worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        location ^~ /bot/ {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Connection "upgrade";
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;

            # by default nginx times out connections in one minute
            proxy_read_timeout 1d;
        }
    }

    include servers/*;
}

Trying it now, seems that CSS still doesn't load and neither images.

deavmi commented 1 week ago

Actually trying now I get this:

image

That is with DOMAIN_SUB_PATH=/bot and proxy_pass=http://sourcebot:3000

brendan-kellam commented 1 week ago

Could you share your nginx config? Also happy to hop on a call to diagnose if that would be easier. Our Discord :)

deavmi commented 1 week ago

Could you share your nginx config? Also happy to hop on a call to diagnose if that would be easier. Our Discord :)

Here it is (I hope it is something glaringly obvious on my side):

image

brendan-kellam commented 1 week ago

Thanks - I will give this a try today

deavmi commented 1 week ago

Thanks - I will give this a try today

Thank you! I don't know what I am doing wrong

brendan-kellam commented 1 week ago

Could you remove the trailing slash from proxy_pass? I.e.:

proxy_pass http://sourcebot:3000;

I hit the same 404 issue as well when the trailing slash is included, but it worked when I removed it. I believe this part of the docs is relevant.

deavmi commented 5 days ago

Could you remove the trailing slash from proxy_pass? I.e.:

proxy_pass http://sourcebot:3000;

I hit the same 404 issue as well when the trailing slash is included, but it worked when I removed it. I believe this part of the docs is relevant.

Hi, sure let me try

deavmi commented 3 days ago

Could you remove the trailing slash from proxy_pass? I.e.:

proxy_pass http://sourcebot:3000;

I hit the same 404 issue as well when the trailing slash is included, but it worked when I removed it. I believe this part of the docs is relevant.

I have done so now, still same error. A 404.

brendan-kellam commented 3 days ago

Dang - tbh I don't know what else to try... would you be able to hop on a call sometime so we can try to diagnose synchronously?