how to redirect public ip to another public ip?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
To redirect a public IP to another public IP, you can use Nginx for example.
You can start by following the steps here on how to install Nginx:
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04
Once Nginx is installed, you’ll need to configure it to perform the redirection:
/etc/nginx/sites-available directory. You can create a new file here, such as redirect.conf, with the following command:sudo nano /etc/nginx/sites-available/redirect.conf
old_ip with the public IP or domain you want to redirect from, and new_ip with the destination public IP or domain.server {
listen 80;
server_name old_ip;
location / {
return 301 http://new_ip$request_uri;
}
}
This configuration listens for HTTP traffic on the old IP and redirects all requests to the new IP.
sites-enabled directory:sudo ln -s /etc/nginx/sites-available/redirect.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Now, any requests made to the old IP should be redirected to the new IP.
Essentially the old IP in this case, will be the IP address of your existing Droplet.
Feel free to share more information about the exact setup that you are trying to achieve and I will be happy to advise you further!
Best,
Bobby
You can use your Droplet’s Webserivce Apache/Nginx to do the redirect
If you can set up a web server on the original server (where the current IP points to), you can configure it to redirect traffic to the new server. This only works for web traffic (HTTP/HTTPS), not for other protocols.
.htaccess with a redirect rule.Here is an example for Nginx:
server {
listen 80;
server_name _;
return 301 http://new-server-ip$request_uri;
}
Replace new-server-ip with the IP address of your new server. Note that this method will not preserve the original IP in the address bar of a browser.
Heya, @9cf6c12952c448868e20a91a0d8b77
As mentioned this can happen in your webserver of choice - Apache or Nginx.
Additionally if you’re using CloudFlare you can use the website redirect there. Have in mind that this works for a domain name and not with the droplet IP itself. I’m mentioning it as an additional option.
https://developers.cloudflare.com/rules/page-rules/how-to/url-forwarding/
Regards
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.