{"id":45295,"date":"2024-03-27T19:12:03","date_gmt":"2024-03-27T19:12:03","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=45295"},"modified":"2024-03-27T19:12:03","modified_gmt":"2024-03-27T19:12:03","slug":"how-to-migrate-all-the-traffic-from-one-to-another-port","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-migrate-all-the-traffic-from-one-to-another-port\/","title":{"rendered":"How to migrate all the traffic from one to another port"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>I am running my app on 10.3.23.23:3000 but the i would like to access at 80 port instead 3000 but the same time i dont want to change app config. what are ohter ways we have<\/p>\n<\/blockquote>\n\n\n\n<p>If you want your application to be accessible on port 80 without changing its configuration (which currently runs on port 3000), you can use a reverse proxy or port forwarding. These methods allow you to keep your application running on its original port while externally it appears to be running on port 80. Here are a few approaches:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Using a Reverse Proxy<\/h3>\n\n\n\n<p>A reverse proxy server sits in front of your application and forwards client requests to the application backend. This is a common way to expose applications running on non-standard ports to standard ports like 80 (HTTP) or 443 (HTTPS).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Nginx<\/h4>\n\n\n\n<p>Here&#8217;s an example configuration for Nginx. If you don\u2019t have Nginx installed, you&#8217;ll need to install it first.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"942\" height=\"456\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-768.png\" alt=\"\" class=\"wp-image-45296\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-768.png 942w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-768-300x145.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-768-768x372.png 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/figure>\n\n\n\n<p>After configuring, restart or reload Nginx for the changes to take effect.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Apache<\/h4>\n\n\n\n<p>If you&#8217;re using Apache as a web server, you can configure it to act as a proxy using <code>mod_proxy<\/code> and <code>mod_proxy_http<\/code>. Here&#8217;s an example configuration:<\/p>\n\n\n\n<p>Ensure that <code>mod_proxy<\/code> and <code>mod_proxy_http<\/code> are enabled, then restart Apache.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"897\" height=\"303\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-769.png\" alt=\"\" class=\"wp-image-45297\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-769.png 897w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-769-300x101.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2024\/03\/image-769-768x259.png 768w\" sizes=\"auto, (max-width: 897px) 100vw, 897px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2. Using iptables for Port Forwarding<\/h3>\n\n\n\n<p>If you&#8217;re running a Linux server and prefer not to use a reverse proxy, you can use <code>iptables<\/code> for port forwarding. This method routes traffic coming into port 80 to port 3000.<\/p>\n\n\n\n<p>Here&#8217;s how to forward port 80 to port 3000 using <code>iptables<\/code>:<\/p>\n\n\n\n<p>To make the rule persistent across reboots, you&#8217;ll need to install <code>iptables-persistent<\/code> or manually add the rule to your startup scripts, depending on your Linux distribution.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">$ sudo apt-<span class=\"hljs-keyword\">get<\/span> update\r\n$ sudo apt-<span class=\"hljs-keyword\">get<\/span> install iptables-persistent\r\n\n$ sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000\n\nSave Your Rules Manually: If you've already installed iptables-persistent or if you need to save new rules after installation, you can save your current iptables rules by executing:\r\n\r\r\n$ sudo netfilter-persistent save<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. Using a Load Balancer<\/h3>\n\n\n\n<p>If you&#8217;re deploying your application in a cloud environment (like AWS, GCP, Azure), you can use their load balancer services to forward traffic from port 80 to port 3000. You&#8217;ll need to set up a load balancer, point it to your application, and configure the listeners to forward traffic from port 80 to port 3000. This approach also gives you the benefit of scaling, SSL termination, and more, depending on the cloud provider&#8217;s offerings.<\/p>\n\n\n\n<p>Each of these methods allows you to expose your application on port 80 without changing the application&#8217;s configuration. Choose the one that best fits your environment and needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am running my app on 10.3.23.23:3000 but the i would like to access at 80 port instead 3000 but the same time i dont want to change app config. what are ohter ways we have If you want your application to be accessible on port 80 without changing its configuration (which currently runs on&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-45295","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/45295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=45295"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/45295\/revisions"}],"predecessor-version":[{"id":45298,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/45295\/revisions\/45298"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=45295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=45295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=45295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}