Skip to Content
GuidesNanoclGet Started3. Configure your proxy

Configure your proxy

You can create proxy rules using the proxy controller to expose your cargo.
A proxy rule allow you to redirect a specific ip address / port or domain name to an upstream of a cargo.

Add proxy rules

To follow up the tutorial you must have a cargo called my-cargo running with port 9001 open as HTTP

Create a file called proxy.deploy-example.yml and copy the following content:

ApiVersion: v0.18 Resources: - Name: deploy-example.com Kind: ncproxy.io/rule/v0.15 Data: Rules: # Domain name for the target - Domain: deploy-example.com # See https://docs.next-hat.com/references/nanocl/objects/resource#proxy-rule-network # For more information about proxy rule network Network: All # List of target by path for maximum flexibility Locations: - Path: / Target: # Canonical target: `namespace.name.c` for a Cargo or `namespace.name.v` for a VM Key: global.my-cargo.c # Cargo port to target Port: 9001

Now let’s create the proxy rule by running:

nanocl state apply -s proxy.deploy-example.yml

You can see existing resources with:

nanocl resource ls

Now we can test that our proxy rule was working

curl --header "Host: deploy-example.com" 127.0.0.1

Should output:

{ "headers": { "x-forwarded-proto": "http", "x-forwarded-for": "127.0.0.1", "accept": "*/*", "x-real-ip": "127.0.0.1", "connection": "close", "x-forwarded-scheme": "http", "host": "deploy-example.com", "user-agent": "curl/8.2.1" }, "envs": { " ": "/bin/nanocl-get-started", "NANOCL_CARGO_INSTANCE": "0", "NANOCL_NODE_ADDR": "192.168.8.102", "HOME": "/", "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "TERM": "xterm", "PORT": "9001", "HOSTNAME": "global.my-cargo-r0-my-cargo-d4e5f6.c", "NANOCL_CARGO_KEY": "global.my-cargo", "NANOCL_CARGO_NAMESPACE": "global", "NANOCL_NODE": "behuman" } }

Now we know how to setup a proxy rule for our cargo enjoy deploying using Nanocl !

Last updated on