Code Monkey home page Code Monkey logo

Comments (6)

jc21 avatar jc21 commented on May 18, 2024 2

@zaywalker Ok I was a little bit mistaken, I found out where the api/websocket requests are happening and it was indeed failing for me too. I found the source of the problem and it's actually Portainers documentation that was wrong. This is the advanced config I'm using and I can get to my consoles now:

location /api/websocket/ {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_pass http://$server:$port;
}

Note that the proxy_pass doesn't need a path and if one is set, it ignored the path of the request when it's forwarded. In this specific case, /api/websocket/exec was being sent to /api/websocket/ and returning 400 errors for me.

from nginx-proxy-manager.

jc21 avatar jc21 commented on May 18, 2024

You're almost there, the advanced config actually gets inserted into the server block and the location / is already forwarded, so all you need is the websocket part, this should work:

location /api/websocket/ {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_pass http://$server:$port/api/websocket/;
}

from nginx-proxy-manager.

SGStino avatar SGStino commented on May 18, 2024

can't seem to get this working.

the generated config looks as following now:

# ------------------------------------------------------------
# portainer.docker
# ------------------------------------------------------------

server {
  set $server 192.168.48.198;
  set $port   9000;

  listen 80;

  server_name portainer.docker;






  access_log /data/logs/proxy_host-2.log proxy;

location /api/websocket/ {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_pass http://$server:$port/api/websocket/;
}

  location / {



    # Proxy!
    include conf.d/include/proxy.conf;
  }
}

However, it's still missing this section:

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

But i can't find a way to inject this into the generated config? Aside from editing the template in the docker image, that is.

from nginx-proxy-manager.

zaywalker avatar zaywalker commented on May 18, 2024

@jc21 Thanks for the answere! I've tried, but unfortunatly it didn't work for me. T_T But that's very good hint to learn how to use custom field. :)

these even I did, but it shows offline.

  location / {
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      proxy_pass http://$server:$port/;
  }
  location /api/websocket/ {
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_http_version 1.1;
      proxy_pass http://$server:$port/api/websocket/;
  }

refer to @SGStino 's way, I've tried edit directly, but it didn't work. I guess

proxy_pass http://$server:$port/; this one is problem.

When I remove that line, I can reach the web, but the web ui doesn't work properly. I can't open container's bash console just like before.

# ------------------------------------------------------------
# portainer.mydomain.com
# ------------------------------------------------------------

server {
  set $server 192.168.123.123;
  set $port   9000;

  listen 80;

  server_name portainer.mydomain.com;



# Asset Caching
  include conf.d/include/assets.conf;


  # Block Exploits
  include conf.d/include/block-exploits.conf;


  access_log /data/logs/proxy_host-9.log proxy;

location /api/websocket/ {
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
   proxy_http_version 1.1;
   proxy_pass http://$server:$port/api/websocket/;
}

  location / {
   proxy_set_header Connection "";
   proxy_http_version 1.1;

    # Proxy!
    include conf.d/include/proxy.conf;
  }
}

Thanks again!

from nginx-proxy-manager.

jc21 avatar jc21 commented on May 18, 2024

@SGStino So this is a bit of a limitation at the moment, you can't specify any custom configuration for hosts that are meant to sit outside of the server block. In your case, map does in fact sit outside of the block and as a result, the $connection_upgrade variable would be available to all nginx configurations options if it were to exist. I haven't found a nice, simple way to illustrate this in the interface yet. The goal of the software is to make life easy for people as much as possible. But I do want to have some more advanced configuration in there for users like yourself.

@zaywalker I'm using the latest Portainer myself (1.16.5 stable Docker version) and I'm not seeing any websocket upgrade requests at all in the interface. Even so, I've added the custom code I first mentioned to my proxy hosts and not only does the config show up on disk as part of the nginx config, it works just fine and reports online.

If you have a look at the proxy config template file you'll see where the advanced_config is placed. You'll also see that there is already a location / { section which cannot exist twice in the same server block.

If v1.19 of Portainer absolutely needs the websocket upgrade, you should only need this advanced config content:

location /api/websocket/ {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_pass http://$server:$port/api/websocket/;
}

When you save the Host in the interface and the host shows "Offline", hover the "Offline" text and you should see the error in the Tooltip. Let me know what that says

from nginx-proxy-manager.

zaywalker avatar zaywalker commented on May 18, 2024

@jc21 Oh thanks for the solution! It works perfectly!! thanks for the help! even I've learn a lot with this! Thansk!

from nginx-proxy-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.