Request help: Joplin server cannot function properly through reverse proxy

joplin/server: 2.2.10

How can nginx be configured to work properly if you want to synchronize through a reverse proxy? thank you

Problem description

  1. When "APP_BASE_URL=http://10.0.0.2:22300”, The synchronization of Joplin and Joplin server is normal

  2. When "APP_BASE_URL=http://10.0.0.2:7002”, Synchronous error reporting through nginx reverse proxy :

Unknown error: <html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> <hr><center>nginx/1.14.2</center> </body> </html> (Code 504)

  • Nginx returns an error message: "upstream timed out"
2021/08/08 08:29:47 [error] 8#8: *4 upstream timed out (110: Connection timed out) while connecting to upstream, client: 10.2.0.2, server: localhost, request: "GET / HTTP/1.1", upstream: "http://10.0.0.2:22300/", host: "10.0.0.2:7002"
10.2.0.2 - - [08/Aug/2021:08:29:47 +0000] "GET / HTTP/1.1" 504 183 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" "-"

The following are the configuration files used by Joplin server and nginx


joplin server docker-compose.yml

version: '3'

services:
    db:
        image: postgres:latest
        container_name: postgres
        restart: unless-stopped
        volumes:
            - /share/Container/data/joplin/joplin-data:/var/lib/postgresql/data
        environment:
            - APP_PORT=22300
            - POSTGRES_PASSWORD=joplin
            - POSTGRES_USER=joplin
            - POSTGRES_DB=joplin
    app:
        image: joplin/server:latest
        depends_on:
            - db
        ports:
            - "22300:22300"
        restart: unless-stopped
        environment:
            - APP_BASE_URL=http://10.0.0.2:7002
            - DB_CLIENT=pg
            - POSTGRES_PASSWORD=joplin
            - POSTGRES_DATABASE=joplin
            - POSTGRES_USER=joplin
            - POSTGRES_PORT=5432
            - POSTGRES_HOST=db

Nginx configuration file

server {
    listen 7002;
    server_name  localhost;
    location / {
        proxy_pass http://10.0.0.2:22300;
        proxy_set_header Host $host;
    }
}

Who can help provide the configuration file of the Nginx reverse proxy Joplin server? thank you

  • The APP_BASE_URL is wrong
    in your example it should be APP_BASE_URL=http://10.0.0.2:7002
  • You need to set the headers for the origin check
  • Redirection everything to /login would not work! You need also to redirect all other paths ...
    For example, requests to http://10.0.0.2:7002/images/Logo.png will end in http://10.0.0.2:7002/login/images/Logo.png

Search the forum for working configs, like for example:

1 Like

Thanks for your help. I tried the profile in your link and fixed it "APP_BASE_URL" is wrong, but the reverse proxy cannot be implemented. The following provides some information. I hope to find the error

Nginx reverse proxy joplin server configuration file

server {
    listen 7002;
    server_name  localhost;

    proxy_read_timeout 720s;
    proxy_connect_timeout 720s;
    proxy_send_timeout 720s;

    client_max_body_size 50m;

    # Proxy headers
    proxy_set_header X-Forwarded-Host $host;
    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-Real-IP $remote_addr;

    # Handle / requests and redirect to a specific port on localhost
    location / {
       proxy_redirect off;
       proxy_pass http://10.0.0.2:22300;
    }
}

Nginx console information

175.155.25.27 - - [02/Aug/2021:15:46:23 +0000] "GET / HTTP/1.1" 499 0 "-" "python-requests/2.25.0" "-"
175.155.25.27 - - [02/Aug/2021:15:46:46 +0000] "GET / HTTP/1.1" 499 0 "-" "python-requests/2.25.0" "-"
175.155.25.27 - - [02/Aug/2021:15:47:09 +0000] "GET / HTTP/1.1" 499 0 "-" "python-requests/2.25.0" "-"
175.155.25.27 - - [02/Aug/2021:15:47:33 +0000] "GET / HTTP/1.1" 499 0 "-" "python-requests/2.25.0" "-"
2021/08/02 15:47:56 [error] 7#7: *5 connect() failed (110: Connection timed out) while connecting to upstream, client: 10.2.0.2, server: localhost, request: "GET /login HTTP/1.1", upstream: "http://10.0.0.2:22300/login", host: "10.0.0.2:7002"
10.2.0.2 - admin [02/Aug/2021:15:47:56 +0000] "GET /login HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15" "-"

You have a network timeout during the connection to 10.0.0.2:22300

I'm very sorry. I didn't understand your following help information before. I suspect the problem is here. Can you help me guide how to modify the nginx configuration file to solve the problems mentioned below? thank you

Redirection everything to /login would not work! You need also to redirect all other paths ...
For example, requests to http://10.0.0.2:7002/images/Logo.png will end in http://10.0.0.2:7002/login/images/Logo.png

I cannot see what you are trying to achieve here. It's difficult to see why you actually need a reverse proxy.

From looking at the above it seems that you have set up Joplin server and the reverse proxy on the same machine, 10.0.0.2? You are then using the reverse proxy just to accept requests for port 7002 and redirect them to port 22300 on that same machine (10.0.0.2)?

Anyway, from looking at your nginx server block it looks odd that the servername is localhost. If nginx is listening on localhost:7002 this seems to me to mean that the only machine that can use this reverse proxy is the machine running the reverse proxy itself. Try replacing server_name localhost; with server_name 10.0.0.2;.

I am in no way an expert at this. I am just comparing your config files with those on this forum that apparently do work.

Also it doesn't help if you keep editing your earlier posts as subsequent replies can then make no sense...

I'm sorry to trouble you. This problem is complex, and I'm not familiar with English, which has led to many edits

As you said, there is really no need for reverse proxy in the LAN. When it works normally, I will replace the LAN IP with the domain name

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