this post was submitted on 18 Nov 2023
1 points (66.7% liked)

Homelab

371 readers
3 users here now

Rules

founded 1 year ago
MODERATORS
 

I've been trying to learn NGINX for a bit now. I tried to make a simple configuration to redirect a subdomain to a specific IP:PORT. However, I fail to manage to make it work properly. Currently, NGINX seems to redirect every request coming into the server to that specific IP:PORT, while also returning the internal IP of the server instead of the proper domain name.

Here's the config :

worker_processes 1;

events {
worker_connections 1024;
}

http {
server {
listen 80;
server_name service.domain.info;

location / {
proxy_pass http://192.168.1.55:81;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

server {
listen 443 ssl;
server_name service.domain.info;
proxy_send_timeout 330s;
proxy_read_timeout 330s;
ssl_certificate c:/folder/folder/webserver-cert-public.crt;
ssl_certificate_key c:/folder/folder/webserver-cert-private.key;
ssl_session_cache shared:WEBSSL:10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
proxy_pass https://192.168.1.55:444;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}

I compared it a bit to other examples i could find on the internet, and couldn't figure out why was wrong. The config should just redirect https://service.domain.info to https://192.168.1.55:444 and http://service.domain.info to http://192.168.1.55:81

If anyone who knows about it more than I do could help, I would appreciate it. Thanks.

top 1 comments
sorted by: hot top controversial new old
[–] Napych@alien.top 1 points 11 months ago

I guess https://192.168.1.55:444 has no valid certificate. You can proxy_pass to http port 80. Alternatively, set up your domain to resolve to 192.168.1.55 for your internal network and use stream proxy or proxy_protocol with valid certificate.