0

I am trying to run a nodejs server by using reverse proxy in Nginx from a private server. lets imagine the port of the server is 192.168.1.10. So when I type 192.168.1.10:12752 to the browser, I want to reach out to the server. However I failed in my all attempts. Here is my configuration file for the server:

server {
    listen 192.168.1.10:80 default_server;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name "";

    location / {
            proxy_pass http://localhost:12752;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

}

Here, I tried lines to be different from above such as

server_name _;
# Tried completely removing server_name section
listen 80;
listen 192.168.1.10:80;

None of them seems to be working. Any help would be appreciated.

Codecygen
  • 121
  • 1
  • 1
  • 10

1 Answers1

0

Hey right now you are telling to nginx to forward 192.168.1.10:80 as default server to -> http://localhost:12752 That mean you should be able to already reach it from http://192.168.1.10

If you want to reach your server on 192.168.1.10:12752 You should change your config to look like this:

server {
    listen 192.168.1.10:12752;

    location / {
            proxy_pass http://localhost:12752;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }
}

The listen property is the ip_address:port you want to nginx to accept connection from where proxy_pass is where nginx redirect the request

leone
  • 123
  • 7
  • Thank you. I understood it now. I can successfully connect to my server however, is there a way to get an SSL key for the server for secure connection? – Codecygen Feb 28 '23 at 10:48
  • Yeah sure, you can make your own using openssl or buy one on some provider, or generate one for free using certbot! I'll recommand you to take a look a certbot – leone Feb 28 '23 at 14:22