Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to use multiple ip address in nginx
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to use multiple ip address in nginx

andikliveandiklive Member
edited September 2016 in Help

Hi, i have some problem with nginx config.

i need one domain, ex. domain.com is have multiple ip address, ex. 5 ip address. but seem im fail to config it, and dont seem have right reference on ne. here my server block.

server { listen 1.1.1.1:80; listen 1.1.1.2:80; listen 1.1.1.3:80; listen 1.1.1.4:80; listen 1.1.1.5:80; server_name domain.com www.domain.com; ..................................... }

after reload and restart nginx, i make simple php script to make api call request to check what ip address that currently i used using _ip-api.com/json, but its only use 1.1.1.1 every time im running check. what i need is i have multiple / different ip address every i make api request.

anyone can help me, which wrong on my server block config. thanks

Comments

  • JustAMacUserJustAMacUser Member
    edited September 2016

    Why not just leave it as listen 80; and Nginx will bind to 0:0:0:0 (all interfaces).

    If you want the domain name to use multiple ones, then in your DNS settings for that domain setup multiple A records, each with one of those five IPs.

  • yomeroyomero Member
    edited September 2016

    No idea for specific addresses, but maybe you can put listen 80 and it should bind to every address.

    If you want to block to some addresses, probably writing some iptables rules should be a good way to go.

    Your script is returning 1.1.1.1 because you are doing a request from your server to internet, which always will use your default address. If you can access your web server via the other addresses, then everything is working as expected.

  • @JustAMacUser said:
    Why not just leave it as listen 80; and Nginx will bind to 0:0:0:0 (all interfaces).

    If you want the domain name to use multiple ones, then in your DNS settings for that domain setup multiple A records, each with one of those five IPs.

    i already did it and no luck, it will work if on diff server. its on one server with /29 and if its work im planning to buy another additional ip address.

    @yomero said:
    No idea for specific addresses, but maybe you can put listen 80 and it should bind to every address.

    If you want to block to some addresses, probably writing some iptables rules should be a good way to go.

    Your script is returning 1.1.1.1 because you are doing a request from your server to internet, which always will use your default address. If you can access your web server via the other addresses, then everything is working as expected.

    nah this part that i dont understand, yes 1.1.1.1 is my default ip address. i already add ip address and success to ping it. how to do that?

  • @andiklive,

    You are trying to have external requests for your domain rotate between a set group of IP address?

  • @JustAMacUser said:
    @andiklive,

    You are trying to have external requests for your domain rotate between a set group of IP address?

    yes, something like that.

    here my case, my domain.com is make request to example.com, and this website example.com is check ip address every request, so i need every im make request to example.com through domain.com i need to have different ip address.

  • JustAMacUserJustAMacUser Member
    edited September 2016

    Ahh...

    So on domain.com you would have to have the program doing the request change the interface it uses. In PHP, for example, you would use curl_setopt and set CURLOPT_INTERFACE.

    You can also do this with iptables in POSTROUTING; including changing it by the user ID making the request.

    Thanked by 2yomero andiklive
  • Nginx handles incoming HTTP requests and has nothing to do with outgoing requests. So adding those won't have any effect. As @JustAMacUser mentioned use curl_setopt($curl, CURLOPT_INTERFACE, "1.1.1.x"); in your PHP code. Before that make sure those additional IP addresses have been assigned to the server's interface.

    Thanked by 2yomero andiklive
  • @JustAMacUser @jesin finally its running perfecly, i just test it with looping and its work. thanks guys all you in LET that its now finnaly working. cheer :)

  • Note that 0.0.0.0 in this context is not all addresses. It means "os pick an address", and you get whatever NIC the os picks -- but just one.

  • williewillie Member

    @topherCantrell thanks for the post and welcome to LET, but note that the previous post in this thread was from September 2016 :O. I'm gonna close the thread.

This discussion has been closed.