planka icon indicating copy to clipboard operation
planka copied to clipboard

NGINX Proxy Pass with SSL Support

Open gamelaster opened this issue 4 years ago • 13 comments

This is my nginx proxy pass configuration for planka (with SSL).

server {
    server_name planka.url;

    listen 443 ssl;                                                         
    listen [::]:443 ssl;

    location / {
        proxy_pass      http://127.0.0.1:1337;
        include         proxy_params;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

gamelaster avatar Aug 13 '20 12:08 gamelaster

Doesn't work for me. How does your docker-compose yml file looks like? 3000-> 1337?

ghost avatar Aug 24 '20 02:08 ghost

@Git-Cluster

ports:
      - 127.0.0.1:1337:1337

So I just bind local 1337 port for 1337 port in container. Also, my docker-compose.yaml is based on original one without any much changes. (BTW, my nginx is running on host)

gamelaster avatar Aug 24 '20 04:08 gamelaster

@Git-Cluster

ports:
      - 127.0.0.1:1337:1337

So I just bind local 1337 port for 1337 port in container. Also, my docker-compose.yaml is based on original one without any much changes. (BTW, my nginx is running on host)

This is what i have

ports: - 127.0.0.1:1337:1337 environment: - BASE_URL=http://127.0.0.1:1337

I even tried ports: - 127.0.0.1:1337:1337 environment: - BASE_URL=http://planka.test.com:1337

And the nginx config is exactly the same as yours

` server { server_name planka.test.com;

listen 443 ssl;                                                         
listen [::]:443 ssl;

location / {
    proxy_pass      http://127.0.0.1:1337;
    include         proxy_params;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

} `

Websockets still ain't connected properly.

Mind if I get some help?

Thanks!

ghost avatar Aug 24 '20 06:08 ghost

Please, can you check what is in your Devtools console (according to gif down)? There should be and error message. 2020-08-24_08-13-38

gamelaster avatar Aug 24 '20 06:08 gamelaster

2websocket.js:124 WebSocket connection to 'wss://planka.test.com/socket.io/?__sails_io_sdk_version=1.2.1&__sails_io_sdk_platform=node&__sails_io_sdk_language=javascript&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
p.doOpen @ websocket.js:124
3websocket.js:124 WebSocket connection to 'wss://planka.test.com/socket.io/?__sails_io_sdk_version=1.2.1&__sails_io_sdk_platform=node&__sails_io_sdk_language=javascript&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
p.doOpen @ websocket.js:124
i.open @ transport.js:84
l.open @ socket.js:250
l @ socket.js:122
l @ socket.js:28
d.open.d.connect @ manager.js:226
(anonymous) @ manager.js:540

This is what I get, indeed it has an error.

ghost avatar Aug 24 '20 06:08 ghost

Very strange. Are you sure that you reloaded your config? Also, which nginx version do you have? This error happens when you don't have this code in your nginx location:

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

gamelaster avatar Aug 24 '20 07:08 gamelaster

Very strange. Are you sure that you reloaded your config? Also, which nginx version do you have? This error happens when you don't have this code in your nginx location:

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

Pretty sure, I did alot of googling and many are certain that this will remove the error but not for me.

ghost avatar Aug 24 '20 07:08 ghost

This is what i have

ports: - 127.0.0.1:1337:1337 environment: - BASE_URL=http://127.0.0.1:1337

I even tried ports: - 127.0.0.1:1337:1337 environment: - BASE_URL=http://planka.test.com:1337

Hi, @Git-Cluster! BASE_URL should contain exactly the same host as server_name from nginx config. Try something like this: BASE_URL=https://planka.test.com (it should have an https scheme and without port).

meltyshev avatar Aug 24 '20 09:08 meltyshev

This is what i have ports: - 127.0.0.1:1337:1337 environment: - BASE_URL=http://127.0.0.1:1337 I even tried ports: - 127.0.0.1:1337:1337 environment: - BASE_URL=http://planka.test.com:1337

Hi, @Git-Cluster! BASE_URL should contain exactly the same host as server_name from nginx config. Try something like this: BASE_URL=https://planka.test.com (it should have an https scheme and without port).

Perfect, it works right now! Thanks everyone for the help!

ghost avatar Aug 24 '20 09:08 ghost

Just in case - here is my working config:

nginx.conf

server {
    listen 80;
    server_name tasks.example.com tasks;
    return 301 https://tasks.example.com$request_uri;
}

map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
}

server {
        listen                  443 ssl;
        server_name             tasks.example.com;
        ssl_certificate         /certs/tasks.example.com.crt;
        ssl_certificate_key     /certs/tasks.example.com.key;

        if ($host != $server_name) {
            return 301 https://tasks.example.com$request_uri;
        }

        location /socket.io {
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection "upgrade";
              proxy_http_version 1.1;
              proxy_pass http://planka:1337/socket.io;
        }

        location / {
                proxy_pass http://planka:1337;
        }
}

in docker-compose.yml BASE_URL=https://tasks.example.com

I never saw any 400 Bad Request in Chrome, however when I switched to Firefox I was finally able to see the 400 error. After then changing the BASE_URL and restarting the Docker container (!) it started working!

tricoos avatar Jun 16 '21 16:06 tricoos

HTTP works but Websocket not

websocket.js:124 
        
       WebSocket connection to 'ws://***/socket.io/?__sails_io_sdk_version=1.2.1&__sails_io_sdk_platform=node&__sails_io_sdk_language=javascript&EIO=3&transport=websocket' failed: 
f.doOpen @ websocket.js:124
o.open @ transport.js:84
l.open @ socket.js:250
l @ socket.js:122
l @ socket.js:28
p.open.p.connect @ manager.js:226
p @ manager.js:69
p @ manager.js:37
c @ index.js:60
(anonymous) @ sails.io.js:884
(anonymous) @ sails.io.js:861
u._connect @ sails.io.js:850
Xe.CALL @ redux-saga-core.esm.js:524
(anonymous) @ redux-saga-core.esm.js:1203
f @ redux-saga-core.esm.js:1271
d @ redux-saga-core.esm.js:1161
c @ redux-saga-core.esm.js:1251
n @ io-6de156f3.js:165
c @ redux-saga-core.esm.js:1251
(anonymous) @ redux-saga-core.esm.js:592
Ue @ redux-saga-core.esm.js:56
Xe.FORK @ redux-saga-core.esm.js:584
(anonymous) @ redux-saga-core.esm.js:1203
f @ redux-saga-core.esm.js:1271
(anonymous) @ redux-saga-core.esm.js:673
Xe.ALL @ redux-saga-core.esm.js:672
(anonymous) @ redux-saga-core.esm.js:1203
f @ redux-saga-core.esm.js:1271
d @ redux-saga-core.esm.js:1161
pt @ redux-saga-core.esm.js:1108
Xe.CALL @ redux-saga-core.esm.js:533
(anonymous) @ redux-saga-core.esm.js:1203
f @ redux-saga-core.esm.js:1271
d @ redux-saga-core.esm.js:1161
c @ redux-saga-core.esm.js:1251
Xe.CALL @ redux-saga-core.esm.js:539
(anonymous) @ redux-saga-core.esm.js:1203
f @ redux-saga-core.esm.js:1271
d @ redux-saga-core.esm.js:1161
pt @ redux-saga-core.esm.js:1108
(anonymous) @ redux-saga-core.esm.js:1367
Ue @ redux-saga-core.esm.js:56
ht @ redux-saga-core.esm.js:1366
u.run @ redux-saga-core.esm.js:1423
(anonymous) @ store.js:28
(anonymous) @ index.js:10
(anonymous) @ index.js:10
Show 17 more frames
websocket.js:124 
        
 

pluveto avatar Aug 22 '22 14:08 pluveto

@pluveto Please post your nginx site config.

gamelaster avatar Aug 22 '22 15:08 gamelaster

@gamelaster Exact same config as @tricoos 's but domain. Finally resolved by reinstall containers without changing nginx config. I guess may be caused by a strange state of the running nodejs process.

pluveto avatar Aug 22 '22 16:08 pluveto

Sample NGIX configuration

https://docs.planka.cloud/docs/Configuration/webserver/NGINX

daniel-hiller avatar Sep 23 '23 02:09 daniel-hiller