# Request help: Joplin server cannot function properly through reverse proxy

**URL:** <https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189>\
**Category:** Support\
**Created:** [2 August 2021 00:09 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189 "2021-08-02T00:09:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![s4j4](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@s4j4](https://discourse.joplinapp.org/u/s4j4)\
**Post date:** [2 August 2021 00:09 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/1 "2021-08-02T00:09:19Z")

</div>

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](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](http://10.0.0.2:7002)”, Synchronous error reporting through nginx reverse proxy :

```auto
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)

```

 ![截屏2021-08-08 19.34.48](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/0/01dc01ce598558c2c9a3e0bab62889daff198d9a.jpeg)

- Nginx returns an error message: "upstream timed out"

```auto
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

```auto
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

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

```

---

<div class="post-metadata">

**Author:** ![s4j4](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@s4j4](https://discourse.joplinapp.org/u/s4j4)\
**Post date:** [2 August 2021 01:52 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/2 "2021-08-02T01:52:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JackGruber](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/jackgruber/32/3231_2.png) [@JackGruber](https://discourse.joplinapp.org/u/JackGruber)\
**Post date:** [2 August 2021 08:12 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/3 "2021-08-02T08:12:56Z")

</div>

- 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:

> [@New Install - Invalid origin error](https://discourse.joplinapp.org/t/new-install-invalid-origin-error/17891/10):
>
> In case anyone is interested this is an nginx "sites-available" reverse-proxy file that uses self-signed certs, diverts port 80 to 443, adds a bit of hardening and also logging. It does work with 2.0.6-beta. { listen 80; server\_name joplin.example.lol; return 301 https://joplin.example.lol$request\_uri; } server { listen 443 ssl http2; server\_name joplin.example.lol; proxy\_read\_timeout 720s; proxy\_connect\_timeout 720s; proxy\_send\_timeout 720s; client\_max\_…

---

<div class="post-metadata">

**Author:** ![s4j4](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@s4j4](https://discourse.joplinapp.org/u/s4j4)\
**Post date:** [2 August 2021 16:03 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/4 "2021-08-02T16:03:06Z")

</div>

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

```auto
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

```auto
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" "-"

```

---

<div class="post-metadata">

**Author:** ![JackGruber](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/jackgruber/32/3231_2.png) [@JackGruber](https://discourse.joplinapp.org/u/JackGruber)\
**Post date:** [3 August 2021 10:23 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/5 "2021-08-03T10:23:58Z")

</div>

> [@s4j4](#):
>
> ... 110: Connection timed out ... upstream: "[http://10.0.0.2:22300/login](http://10.0.0.2:22300/login)" ...

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

---

<div class="post-metadata">

**Author:** ![s4j4](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@s4j4](https://discourse.joplinapp.org/u/s4j4)\
**Post date:** [8 August 2021 08:59 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/8 "2021-08-08T08:59:53Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![dpoulton](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/dpoulton/32/29723_2.png) [@dpoulton](https://discourse.joplinapp.org/u/dpoulton)\
**Post date:** [8 August 2021 11:52 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/9 "2021-08-08T11:52:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![s4j4](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@s4j4](https://discourse.joplinapp.org/u/s4j4)\
**Post date:** [8 August 2021 12:06 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/10 "2021-08-08T12:06:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/1/c/1c948e33314e232a0927789508474d8624f4270b.png) [@system](https://discourse.joplinapp.org/u/system)\
**Post date:** [7 September 2021 12:06 UTC](https://discourse.joplinapp.org/t/request-help-joplin-server-cannot-function-properly-through-reverse-proxy/19189/11 "2021-09-07T12:06:45Z")

</div>

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