"Invalid URL" after Login

Using an Ubuntu 18.04 vps for this.
Dockered Joplin with the latest release (2.9.1)
Nginx as a reverse Proxy.

Docker compose up works fine, I get the login page but when trying to login with admin@localhost I get the error: Invalid URL.
Sync in the desktop app with the default login credentials work! Ofc I dont want to use them though.
The Error in the log:

2022-08-04 06:40:30: [error] App: Middleware error on /login: TypeError: Invalid URL
app_1  |     at new NodeError (node:internal/errors:371:5)
app_1  |     at onParseError (node:internal/url:552:9)
app_1  |     at new URL (node:internal/url:628:5)
app_1  |     at acceptOrigin (/home/joplin/packages/server/src/app.ts:122:21)
app_1  |     at Object.origin (/home/joplin/packages/server/src/app.ts:189:8)
app_1  |     at cors (/home/joplin/packages/server/node_modules/@koa/cors/index.js:60:24)
app_1  |     at dispatch (/home/joplin/packages/server/node_modules/koa-compose/index.js:42:32)
app_1  |     at /home/joplin/packages/server/src/app.ts:181:10
app_1  |     at Generator.next (<anonymous>)
app_1  |     at /home/joplin/packages/server/dist/app.js:8:71 {
app_1  |   input: 'null',
app_1  |   code: 'ERR_INVALID_URL'
app_1  | }

Following Config files were used:
docker-compose.yml:

version: '3'
services:
    db:
        restart: unless-stopped
        image: postgres:13.1
        ports:
            - "5432:5432"
        volumes:
            - /foo/bar/joplin-data:/var/lib/postgresql/data
        environment:
            - POSTGRES_PASSWORD=*****
            - POSTGRES_USER=*****
            - POSTGRES_DB=joplin
    app:
        environment:
            - APP_BASE_URL=https://joplin.mydomain.com
            - APP_PORT=22300
            - POSTGRES_PASSWORD=******
            - POSTGRES_DATABASE=joplin
            - POSTGRES_USER=*****
            - POSTGRES_PORT=5432 
            - POSTGRES_HOST=db
            - DB_CLIENT=pg
        restart: unless-stopped
        image: etechonomy/joplin-server:latest
        ports:
            - "22300:22300"
        depends_on:
            - db

nginx conf file:

server {
    server_name joplin.mydomain.com;
	 location /login {
                   proxy_set_header host $host;
                   proxy_set_header X-Real-IP $remote_addr;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                   proxy_set_header X-Forwarded-Proto $scheme;
                   proxy_set_header X-Forwarded-Port $server_port;
                   proxy_set_header X-Forwarded-Host $host;
                   client_max_body_size 400M;
                   proxy_pass http://127.0.0.1:22300/login;
               }
			   
    location / {
        proxy_pass http://127.0.0.1:22300/;
        proxy_set_header X-Forwarded-Host $host:22300;
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Forwarded-Port $server_port;
		proxy_set_header X-Real-IP $remote_addr;
        client_max_body_size 400M;
    }
	proxy_read_timeout 720s;
	proxy_connect_timeout 720s;
	proxy_send_timeout 720s;

	# log files
	access_log /var/log/nginx/your.domain.com.access.log;
	error_log /var/log/nginx/your.domain.com.error.log;
	
	SOME CERTBOT STUFF I CUT HERE
	
   

}

I hope someone can help me, as I have not found any solution online.

The location should be just /, and you could add proxy_redirect off directive, just to be on the safe side.

I'm on mobile now so if this doesn't solve your problem, I'll diff my working configs with yours.

Thank you for your help. I tried your Ideas, as you can see in the config below. Still the error persists. It would be great if u could diff your version with mine.

server {
    server_name joplin.mydomain.com;		   
    location / {
        proxy_pass http://127.0.0.1:22300/;
        proxy_set_header X-Forwarded-Host $host:22300;
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Forwarded-Port $server_port;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_redirect off;
        client_max_body_size 400M;
    }
	proxy_read_timeout 720s;
	proxy_connect_timeout 720s;
	proxy_send_timeout 720s;

I know something better, here's my actual anonymized config file: server { listen 80; server_name joplin.example.com; return 301 ht - Pastebin.com

Also, in your .env your APP_BASE_URL should look like this:
APP_BASE_URL=https://joplin.example.com (your actual url should be the way it is, the point is the format of the parameter, for instance, no / at the end).

This is my actual setup my Joplin Server works from day 1.

Thanks for the fast reply. I structured my conf file as you did but I still have the same error. Even just clicking login, without any info in the login fields results in the invalid url error. Maybe it is not the nginx causing the problem (seeing the logs of running the docker with the error presented there)


app_1  | 2022-08-05 11:28:12: [error] App: Middleware error on /login: TypeError: Invalid URL
app_1  |     at new NodeError (node:internal/errors:371:5)
app_1  |     at onParseError (node:internal/url:552:9)
app_1  |     at new URL (node:internal/url:628:5)
app_1  |     at acceptOrigin (/home/joplin/packages/server/src/app.ts:122:21)
app_1  |     at Object.origin (/home/joplin/packages/server/src/app.ts:189:8)
app_1  |     at cors (/home/joplin/packages/server/node_modules/@koa/cors/index.js:60:24)
app_1  |     at dispatch (/home/joplin/packages/server/node_modules/koa-compose/index.js:42:32)
app_1  |     at /home/joplin/packages/server/src/app.ts:181:10
app_1  |     at Generator.next (<anonymous>)
app_1  |     at /home/joplin/packages/server/dist/app.js:8:71 {
app_1  |   input: 'null',
app_1  |   code: 'ERR_INVALID_URL'
app_1  | }

At this point I'm sure it's not the fault of Nginx. Although I don't know your setup, the fact that you're looking at Node logs tells me you're up to no good.:smiley:

Kidding aside, you shouldn't/wouldn't have to do that. Joplin Server is a deployed via a simple docker compose file and the environment file, other than that a reverse proxy config is required. If you did something else/not like this, the problem lies there.

I would advise deleting your current setup and redeploy it as it is "meant to be deployed".

I did and reinstalled everything (easy to do) and the error persists. The log is just the print out by starting docker-compose up without the detached parameter. Maybe someone else has an idea?

If you have a publicly available server where you want to set this up and give me an account I gladly take a look (and have done for quite a few other members on this forum, as well).

Thank you for the offer, but I cant let you do that unfortunately. I run several other services/pages on that server and cant let someone else on there.

I found this issue on github which is prty much my issue. The "workaround" that was suggested is:
"RequestHeader set Origin "https://" early" but I cant make sense of that. Can someone make the solution a little clearer for me?

This is an Apache directive that doesn't translate directly to Nginx. Something similar can be achieved by using the HTTP headers module in Nginx. You need to at this to the config (to the server block), thus enabling CORS:

add_header Access-Control-Allow-Origin *;

Though this is curious why anyone ould need this workaround. I've set up JS for folks with pretty diverse environments, always with Nginx and never needed anything like that.

thanks. This does not work for me but it was worth a try

I would have been surprised if it did, honestly, it is a little more complex than that, that is why I said it doesn't translate directly. A few other examples you may use as a starting point: Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs ยท GitHub

Edit: another one, from here: Major breaking change in coming Joplin Server 2.0 - #115 by BoxingOctopus (from comment 109). I suspect the URL in your .env doesn't look like it was supposed to (e.g http:// instead of https://). Frankly, if it's not https you should just copy your original nginx config back (or mine, for that matter), change it to https then rebuild it and it will work.

Got it working by adding this

    # Simple requests
    if ($request_method ~* "(GET|POST)") {
      add_header "Access-Control-Allow-Origin"  *;
    }

    # Preflighted requests
    if ($request_method = OPTIONS ) {
      add_header "Access-Control-Allow-Origin"  *;
      add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
      add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
      return 200;
    }

to location /

thank you so much for your help and patience. you are my hero

I'm glad it worked out! Please mark the relevant comment as the solution so others can use that as a starting point.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.