{"id":26767,"date":"2022-01-18T09:17:31","date_gmt":"2022-01-18T09:17:31","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=26767"},"modified":"2025-05-17T06:09:44","modified_gmt":"2025-05-17T06:09:44","slug":"how-to-change-listening-nginx-port","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-change-listening-nginx-port\/","title":{"rendered":"How to change listening Nginx Port"},"content":{"rendered":"<h1>How to change listening Nginx Port<\/h1>\n<p><strong>NGINX<\/strong> is a high-performance, open-source web server and reverse proxy server. It is well-known for its speed, scalability, and efficiency, particularly when handling a large number of concurrent connections.<\/p>\n<h2><strong>Error Indication<\/strong><\/h2>\n<p>You get the following error when you start Nginx server.<\/p>\n<p><strong>ubuntu nginx[4686]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)<\/strong><\/p>\n<p>The problem root cause is that the listening port is already in use. To change the port that NGINX listens on, you need to modify the NGINX configuration file.<\/p>\n<h2>Steps<\/h2>\n<p>Steps to change the port are as follows:<\/p>\n<p>Open the NGINX Configuration File: You can use any text editor like nano or vim. The main configuration file is usually located at<\/p>\n<p>\/etc\/nginx\/nginx.conf, but some systems might use<\/p>\n<p>\/etc\/nginx\/sites-available\/default<\/p>\n<p>or<\/p>\n<p>\/etc\/nginx\/conf.d\/default.conf<\/p>\n<p>&nbsp;<\/p>\n<p>For example, open the NGINX configuration file with nano:<\/p>\n<p><strong>$ sudo nano \/etc\/nginx\/nginx.conf<\/strong><\/p>\n<p>Find the <strong>listen<\/strong> Directive: Look for the listen directive in the configuration file. This tells NGINX which port it should be listening on. By default, it might look like this:<\/p>\n<pre><code class=\"\" data-line=\"\">server {\n        listen 80;\n        server_name example.com;\n        ...\n}<\/code><\/pre>\n<p>Change the Port: Modify the listen directive to the new port you want NGINX to listen on. For example, to change it to port 8080, you would modify it like this:<\/p>\n<pre><code class=\"\" data-line=\"\">server {\n      listen 8080;\n      server_name example.com;\n      ...\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Save and Exit: After making the change, save the file and exit the editor. If you&#8217;re using nano, press <strong>CTRL + O<\/strong> to save, then <strong>CTRL + X<\/strong> to exit.<\/p>\n<p>Check NGINX Configuration<\/p>\n<p>It&#8217;s always a good idea to check if the configuration is valid before restarting NGINX. Run:<\/p>\n<p><strong>$ sudo nginx -t<\/strong><\/p>\n<p>If the output says the configuration is OK, you can proceed. If there are errors, fix them before proceeding.<\/p>\n<p>Restart NGINX<\/p>\n<p>After making the changes, restart NGINX for the changes to take effect:<\/p>\n<p><strong>$ sudo systemctl restart nginx<\/strong><\/p>\n<p>Allow the New Port through the Firewall (if applicable): If you&#8217;re using a firewall (e.g., ufw), make sure the new port is allowed.<br \/>\nFor example, if you changed to port 8080:<\/p>\n<p><strong>$ sudo ufw allow 8080<\/strong><\/p>\n<p>Now, NGINX should be listening on the new port! To verify, you can check with:<\/p>\n<p><strong>$ sudo netstat -tuln | grep 8080<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to change listening Nginx Port NGINX is a high-performance, open-source web server and reverse proxy server. It is well-known for its speed, scalability, and efficiency, particularly when handling a large number of concurrent connections. Error Indication You get the following error when you start Nginx server. ubuntu nginx[4686]: nginx: [emerg] bind() to 0.0.0.0:80 failed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-26767","post","type-post","status-publish","format-standard","hentry","category-linux","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/26767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=26767"}],"version-history":[{"count":4,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/26767\/revisions"}],"predecessor-version":[{"id":27882,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/26767\/revisions\/27882"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=26767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=26767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=26767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}