ItzCrazyKns / Perplexica

Perplexica is an AI-powered search engine. It is an Open source alternative to Perplexity AI
MIT License
16.24k stars 1.52k forks source link

Use with service like ngrok for remote access from off LAN. #142

Open lafintiger opened 6 months ago

lafintiger commented 6 months ago

Is your feature request related to a problem? Please describe. Yes, I followed the instructions for lan access and that worked fine for accessing via lan. But when I use ngrok when I access the page the page loads but hangs on the spinning circle in the middle.

Describe the solution you'd like Instruction on how to get this awesome project accessible from off the lan. I would like to be at work and still access this from my server that I have running it.

Describe alternatives you've considered I tried ngrok and loclx. I only get the spinning circle.

Additional context None.

ItzCrazyKns commented 6 months ago

You just need to replace 127.0.0.1 in the docker compose file with the actual domain assigned to your backend and rebuild the images (making sure the previous ones are deleted).

delfireinoso commented 5 months ago

If anyone get this working should share

jonas-w commented 5 months ago

Basically @ItzCrazyKns posted the solution.

I don't know about ngrok, but likely your problem is that you are only forwarding the frontend and not the backend, I created this nginx config file for my host:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
upstream perplexica-frontend {
    server localhost:3000;
}
upstream perplexica-backend {
    server localhost:3001;
}

server {
    server_name <redacted>;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    location / {
        proxy_pass http://perplexica-frontend;
        include proxy_params;
    }

    location /api {
        proxy_pass http://perplexica-backend/api;
        include proxy_params;
    }

    location /ws {
        proxy_pass http://perplexica-backend;
        include proxy_params;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

This does the following: Proxy requests to the frontend, except /api and /ws which are proxied to the backend. And in the docker-compose.yml I set the following:

        - NEXT_PUBLIC_API_URL=https://<redacted>/api
        - NEXT_PUBLIC_WS_URL=wss://<redacted>/ws
delfireinoso commented 5 months ago

You can elaborate? Where you put this file, and wich is the name, in the compose tree under /Perplexica/ ? Or Nginx should be installed separated?

jonas-w commented 5 months ago

You can elaborate? Where you put this file, and wich is the name, in the compose tree under /Perplexica/ ? Or Nginx should be installed separated?

nginx is a reverse proxy like Caddy, Haproxy. Nginx just happens to be what I used. It is something extra you need to have, but If you have another reverse proxy already installed you can use that.

delfireinoso commented 5 months ago

nginx is a reverse proxy like Caddy, Haproxy. Nginx just happens to be what I used. It is something extra you need to have, but If you have another reverse proxy already installed you can use that.

I'll try to install Nginx and go this route, perhaps this time I'm lucky. we tried Cloudflare tunnels with not luck. It would be easier if Perplexica was designed to run remote.

delfireinoso commented 5 months ago

I'll try to use Caddy as I'm using zrok for the other projects. I'll try to translate to their syntax

one question: is the public name on Nginx? So I'll need to put this public name on the Perplexica compose file

Great to know

Deathproof76 commented 1 month ago

fyi for anyone looking how to get caddy reverse proxy working. caddy seems to handle websockets automagically:

In the docker env for the frontend:

  perplexica-frontend:
    image: xwukong/perplexica-frontend:latest ## I used this image because latest official main (as of today Oct 3, 2024) seemed to have a bug https://github.com/ItzCrazyKns/Perplexica/issues/385 and I was lazy
    environment:
        - NEXT_PUBLIC_API_URL=https://perplexicabackend.yourdomain.com/api
        - NEXT_PUBLIC_WS_URL=wss://perplexicabackend.yourdomain.com
    ......

And for the Caddyfile I used two different subdomains:

perplexicafrontend.yourdomain.com {
    reverse_proxy 192.168.0.208:3000 #(the local ip of my server (my caddy runs on another device) plus the stardard port for the frontend)
}

perplexicabackend.yourdomain.com {
    reverse_proxy 192.168.0.208:3001 #(the local ip of my server (my caddy runs on another device) plus the stardard port for the backend)
}

And via perplexicafrontend.yourdomain.com it's available.

btw: of course I secured it. for example via:

perplexicafrontend.yourdomain.com {
    @denied not remote_ip 192.168.0.0/16 172.16.0.0/12 172.27.66.2/24 10.0.0.0/8 127.0.0.1/8
    respond @denied "Nope" 403
    reverse_proxy 192.168.0.208:3000
}

perplexicabackend.yourdomain.com {
    @denied not remote_ip 192.168.0.0/16 172.16.0.0/12 172.27.66.2/24 10.0.0.0/8 127.0.0.1/8
    respond @denied "Nope" 403
    reverse_proxy 192.168.0.208:3001
}

so it can only be reached via a machine in your lan or for example if you use wireguard to connect to your home network

edit: I spawned a second instance with other front and backend ports and reproduced the setup with "the former https instead of ws in the docker environment" (it is now edited out), which seemed to be a fluke, maybe some db leftovers or standard port related. Use of for example - NEXT_PUBLIC_WS_URL=wss://perplexicabackend.yourdomain.com wss is needed. In short I corrected an error, everything works now.