[ Experiments ]

Experiments with Nginx Forwarding

Created:

Updated:

Read: 1 min (156 words)

Tags:

Direct Request to Localhost (IP-based)

Client Command

1
curl http://localhost:3000

Server Request

GET / HTTP/1.1
Host: localhost:3000
User-Agent: curl/7.88.1
Accept: */*

Direct Request to 127.0.0.1 (IP-based)

Client Command

1
curl http://127.0.0.1:3000

Server Request

GET / HTTP/1.1
Host: 127.0.0.1:3000
User-Agent: curl/7.88.1
Accept: */*

Request Through Nginx Proxy (Without Custom Headers)

Client Command

1
curl http://test.mxroute.xyz

Nginx Configuration

1
2
3
4
5
6
7
server {
    listen 80;
    server_name test.mxroute.xyz;
    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

Server Request

GET / HTTP/1.0
Host: 127.0.0.1:3000
Connection: close
User-Agent: curl/8.10.1
Accept: */*

Request Through Nginx Proxy (With Custom Headers)

Client Command

1
curl http://test.mxroute.xyz

Nginx Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
server {
    listen 80;
    server_name test.mxroute.xyz;
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Server Request

GET / HTTP/1.0
Host: test.mxroute.xyz
X-Forwarded-For: 103.15.228.94
X-Forwarded-Proto: http
Connection: close
User-Agent: curl/8.10.1
Accept: */*