[GH-ISSUE #506] Automagic routing for docker-containers #432

Closed
opened 2026-02-26 06:32:49 +03:00 by kerem · 2 comments
Owner

Originally created by @Xantios on GitHub (Jul 15, 2020).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/506

Is your feature request related to a problem? Please describe.

The problem if any, is my own OCD & lazyness.

Software like Treafik and JWilder's nginx proxy all have the ability to automatically route to a docker-container based on a label or env flag.

My goal would be to have similar behaviour in nginx-proxy-manager so i tried implementing something like that.

However I cant seem to be able to POST to the API.

Describe the solution you'd like
As far as i can tell it should be possible to do a POST request to /api/nginx/proxy-hosts

{
"domain_names": ["VOORBEELDDDDDD"],
"forward_scheme":"http",
"forward_host":"10.13.37.128",
"forward_port":5000,
"access_list_id":"0",
"certificate_id":0,
"advanced_config":"",
"locations":[],
"block_exploits":false,
"caching_enabled":false,
"allow_websocket_upgrade":false,
"http2_support":false,
"hsts_enabled":false,
"hsts_subdomains":false,
"ssl_forced":false
}

Is telling me i miss a token, fair enough. however if i try to post to http://server:3081/tokens it also tells me to get lost.

HTTP/1.1 405 Not Allowed
Connection: keep-alive
Content-Length: 154
Content-Type: text/html
Date: Wed, 15 Jul 2020 20:22:30 GMT
Server: openresty

Any way to get this up and running?

Describe alternatives you've considered
Snooping around in the code. but cant seem to find why one would do this

Update: one should use the /api/tokens/ to get the token. now lets try to create a host again. will update asap

Update: I can now create a vhost from a shell, so i should be able to manage it from my Docker events. Is there any interrest for a PR ?

Originally created by @Xantios on GitHub (Jul 15, 2020). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/506 **Is your feature request related to a problem? Please describe.** The problem if any, is my own OCD & lazyness. Software like Treafik and JWilder's nginx proxy all have the ability to automatically route to a docker-container based on a label or env flag. My goal would be to have similar behaviour in nginx-proxy-manager so i tried implementing something like that. However I cant seem to be able to POST to the API. **Describe the solution you'd like** As far as i can tell it should be possible to do a POST request to ```/api/nginx/proxy-hosts``` ```json { "domain_names": ["VOORBEELDDDDDD"], "forward_scheme":"http", "forward_host":"10.13.37.128", "forward_port":5000, "access_list_id":"0", "certificate_id":0, "advanced_config":"", "locations":[], "block_exploits":false, "caching_enabled":false, "allow_websocket_upgrade":false, "http2_support":false, "hsts_enabled":false, "hsts_subdomains":false, "ssl_forced":false } ``` Is telling me i miss a token, fair enough. however if i try to post to http://server:3081/tokens it also tells me to get lost. ``` HTTP/1.1 405 Not Allowed Connection: keep-alive Content-Length: 154 Content-Type: text/html Date: Wed, 15 Jul 2020 20:22:30 GMT Server: openresty ``` Any way to get this up and running? **Describe alternatives you've considered** Snooping around in the code. but cant seem to find why one would do this Update: one should use the ```/api/tokens/``` to get the token. now lets try to create a host again. will update asap Update: I can now create a vhost from a shell, so i should be able to manage it from my Docker events. Is there any interrest for a PR ?
kerem 2026-02-26 06:32:49 +03:00
Author
Owner

@Xantios commented on GitHub (Jul 15, 2020):

Update: Turns out you can do this !

#!/bin/bash

# Notice: I use httpie for this (brew install httpie)

HOST="http://localhost:3081"
USER="admin@example.com"
PASS="changeme"

echo "==> Logging in... "
TOKEN=`http post $HOST/api/tokens identity=$USER secret=$PASS --body | python -mjson.tool | grep token | cut -d: -f2 | sed -e 's/^[ \t]*//' | tr -d '"' `

echo "==> Creating host "
http post $HOST/api/nginx/proxy-hosts \
 Authorization:"Bearer ${TOKEN}" \
 domain_names:='["kaas"]' forward_scheme="http" forward_host="10.13.37.132" forward_port="5000" \
 access_list_id="0" certificate_id="0" advanced_config="" locations:="[]" block_exploits="false"
<!-- gh-comment-id:659018994 --> @Xantios commented on GitHub (Jul 15, 2020): Update: Turns out you can do this ! ```bash #!/bin/bash # Notice: I use httpie for this (brew install httpie) HOST="http://localhost:3081" USER="admin@example.com" PASS="changeme" echo "==> Logging in... " TOKEN=`http post $HOST/api/tokens identity=$USER secret=$PASS --body | python -mjson.tool | grep token | cut -d: -f2 | sed -e 's/^[ \t]*//' | tr -d '"' ` echo "==> Creating host " http post $HOST/api/nginx/proxy-hosts \ Authorization:"Bearer ${TOKEN}" \ domain_names:='["kaas"]' forward_scheme="http" forward_host="10.13.37.132" forward_port="5000" \ access_list_id="0" certificate_id="0" advanced_config="" locations:="[]" block_exploits="false" ```
Author
Owner

@Xantios commented on GitHub (Jul 20, 2020):

Update: I wrote a little NodeJS utility to talk to the API and do some 'fancy' auto routing

https://github.com/Xantios/nginx-proxy-manager-assistent

<!-- gh-comment-id:660952688 --> @Xantios commented on GitHub (Jul 20, 2020): Update: I wrote a little NodeJS utility to talk to the API and do some 'fancy' auto routing https://github.com/Xantios/nginx-proxy-manager-assistent
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#432
No description provided.