Perplexica icon indicating copy to clipboard operation
Perplexica copied to clipboard

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

Open lafintiger opened this issue 1 year ago • 8 comments
trafficstars

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.

lafintiger avatar May 25 '24 00:05 lafintiger

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

ItzCrazyKns avatar May 25 '24 02:05 ItzCrazyKns

If anyone get this working should share

delfireinoso avatar May 30 '24 08:05 delfireinoso

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

jonas-w avatar May 30 '24 21:05 jonas-w

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?

delfireinoso avatar Jun 08 '24 10:06 delfireinoso

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.

jonas-w avatar Jun 12 '24 12:06 jonas-w

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 avatar Jun 12 '24 16:06 delfireinoso

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

delfireinoso avatar Jun 23 '24 08:06 delfireinoso

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.

Deathproof76 avatar Oct 05 '24 23:10 Deathproof76

Should be fixed by https://github.com/ItzCrazyKns/Perplexica/commit/217736d05afeb5b10bb61827203f189b55b2c6cc, follow the update guide to update Perplexica to the latest version. Happy searching!!

ItzCrazyKns avatar Mar 20 '25 08:03 ItzCrazyKns

The entire backend has been removed, everything is now handled by the frontend.

ItzCrazyKns avatar Mar 20 '25 08:03 ItzCrazyKns