Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to forward port 80 to 8080 using NGINX

I have been trying to set up NGINX for the first time and I need to enable port forwarding from 80 to 8080 for my website. However, after many attempts I have obtained nothing. Here is my latest attempt:

I followed the steps here accordingly: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3

The difference is the fact that my nginx.conf file contains:

server{
    listen 80;
    server_name myWebsiteName;

    access_log /home/path_to_site/access.log;
    error_log /home/path_to_site/error.log;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Is this the right file content? Am I using the wrong tutorial?

Thanks!

like image 472
Anamaria Cotirlea Avatar asked Jan 21 '26 10:01

Anamaria Cotirlea


1 Answers

The example you provided contains some mistakes:

  • 0.0.0.0 is not the same as localhost, you probably want this IP-address to be 127.0.0.1
  • 8082 does not match the port you want to forward to (which, I believe, is 8080).

A fixed example could be:

server{
   listen 80;
   server_name myWebsiteName;

   access_log /home/path_to_site/access.log;
   error_log /home/path_to_site/error.log;

   location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

In this example all incoming requests on port 80 will be proxied to port 8080 on this host.

Despite this being possible, is this really the solution you are looking for? Is it possible to change the listening port for the application that you are proxying to?

like image 56
DJFliX Avatar answered Jan 23 '26 07:01

DJFliX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!