Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forwarding port 80 to 8080 using NGINX [closed]

I'm using LEMP stack and Node JS on my debian server. Nginx works on port 80 and Node JS on 8080. I created new subdomain: cdn.domain.com for nodejs app. Currently I can access to Node JS application only like cdn.domain.com:8080/. What I want to do is to configure Nginx so that, when I enter to cdn.domain.com I can get app working on port 80. I think it can be done using nginx upstream. But I can't figure out how.

like image 551
heron Avatar asked Jul 21 '14 09:07

heron


People also ask

Does Nginx use port 80?

By default, the Nginx HTTP server listens for inbound connections and connects to port 80, which is the default web port.

Can Nginx be used as forward proxy?

NGINX was initially designed as a reverse proxy server. However, with continuous development, NGINX also serves as one of the options to implement the forward proxy. The forward proxy itself is not complex, the key issue it addresses is how to encrypt HTTPS traffic.

How does nginx reverse proxy work?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.


2 Answers

As simple as like this,

make sure to change example.com to your domain (or IP), and 8080 to your Node.js application port:

server {     listen 80;     server_name example.com;      location / {         proxy_set_header   X-Forwarded-For $remote_addr;         proxy_set_header   Host $http_host;         proxy_pass         "http://127.0.0.1:8080";     } } 

Source: https://eladnava.com/binding-nodejs-port-80-using-nginx/

like image 170
Nyi Nyi Avatar answered Sep 23 '22 20:09

Nyi Nyi


NGINX supports WebSockets by allowing a tunnel to be setup between a client and a backend server. In order for NGINX to send the Upgrade request from the client to the backend server, Upgrade and Connection headers must be set explicitly. For example:

# WebSocket proxying map $http_upgrade $connection_upgrade {     default         upgrade;     ''              close; }   server {     listen 80;      # The host name to respond to     server_name cdn.domain.com;      location / {         # Backend nodejs server         proxy_pass          http://127.0.0.1:8080;         proxy_http_version  1.1;         proxy_set_header    Upgrade     $http_upgrade;         proxy_set_header    Connection  $connection_upgrade;     } } 

Source: http://nginx.com/blog/websocket-nginx/

like image 26
Tan Hong Tat Avatar answered Sep 25 '22 20:09

Tan Hong Tat