How can I bind a process to a floating IP?

August 22, 2018 1.9k views
Applications Ubuntu

How can I bind a process(i.e. Web server) to a floating IP address? I want to configure NGINX to listen only on the floating IP. However, Ubuntu doesn’t detect the floating IP at all, and NGINX gives an error whenever I try:

nginx: [emerg] bind() to floating_ip:443 failed (99: Cannot assign requested address)

The config I’m using is:

    server{
        listen floating_ip:443 ssl;
        ssl_certificate /var/www/.acme.sh/domain_name.com/fullchain.cer;
        ssl_certificate_key /var/www/.acme.sh/domain_name.com/domain_name.com.key;
        location /{
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
            #proxy_set_header scheme $scheme;
            proxy_set_header X_FORWARDED_PROTO $scheme;
            proxy_pass http://127.0.0.1:80;
        }
    }
1 comment
1 Answer

Thanks to X40C for finding this:

The answer already exists here.

TL;DR

Run the following from your droplet to find the IP to bind to:

curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address
Have another answer? Share your knowledge.