Nginx Reverse proxy translate domain to ip - nginx-reverse-proxy

I'm new with nginx, but i'm trying to build a reverse proxy that could do something like this:
Whenever a request arrives to a domain name like this in my nginx reverse proxy server:
http://dn.55-32.mydomain.name/path/file.cfg
Parse the 55-32 and forward the request to an internal ip.
http://10.10.55.32/path/file.cfg
The 55-32 represent that las octects XX.XX.55.32 to the forwarded server.
Is there a way to build such a behavior?

Finally i made it wokr with this configuration:
server {
listen 443 ssl http2 default_server;
server_name ~^dn\.(?<octet1>.+)-(?<octet2>.+)\.mydomain\.com$;
location / {
set $var http://10.10.$octet1.$octet2;
proxy_pass $var;
}
}
Maybe this could be helpful for someone...
Ricardo

Related

Binding media server to a different host

I am trying to reverse proxy my local home NAS.
What I would like to do is, now my media server listens on nas:8096, but I would like to reverse proxy it to be media.
I tried to bind it with Nginx Proxy Manager, but it doesn't seem to work:
server {
listen 80;
location media/ {
proxy_pass http://192.168.0.100:8096;
}
}
I know its a stupid try... :D
Thanks.

How to make nginx passthrough on 443 and redirect 80 to 443?

I have a winstone server (Jenkins) listening on 8443.
Jenkins has a valid cert, and Jenkins is doing the cert termination successfully:
JENKINS_ARGS="--httpPort=-1 --httpsKeyStore=/secure/jenkins.keystore --httpsKeyStorePassword=MY_PASSWORD --httpsPort=8443"
The only problem is that users now have to go:
https://example.com:8443
I don't want that port number in the URL.
I want:
https://example.com:8443 -> https://example.com
https://example.com -> https://example.com
http://example.com -> https://example.com
So I figure I'll run nginx on the same instance that is running Jenkins.
So my question is:
Do I have to reconfigure jenkins to NOT do cert termination so that nginx does it only?
Can nginx redirect 80 and 443 to localhost:8443 without a cert (Since Jenkins is doing cert termination)?
Do BOTH nginx AND Jenkins need to do cert termination?
Sorry for those similar questions.
I'm pretty sure an AWS ELB cannot replace what nginx is doing here, but I thought I'd throw it out there, in case an ELB can solve this for me too.
1) No, you can have Nginx Stream the connection directly to the Jenkins using the Stream Module.
Do note this was added in 1.9.0 but is not part of the default build so you might have to build it yourself.
It works a lot like an http server block but you have to set it up outside of the http block.
stream {
upstream jenkins_server {
server jenkins:443;
}
server {
listen 443;
proxy_pass jenkins_server;
}
}
2) You do not need a cert on nginx but you should have a http server block for port 80 that does a 301 to the 443 stream talked about in answer part 1.
server {
listen 80;
server_name your_server_name_here;
return 301 https://$host$request_uri;
}
3) No, you don't as you can use the nginx stream to passthru the ssl from the client to the Jenkins server.

Passing SSL traffic through corporate proxy using nginx

I have done some resarch for this matter and there are some unaswered question regarding my issue, however I managed to solve half of what is needed (thanks to people on the site).
Scenerio:
I have Nginx as a reverse proxy in internal corporate network. I need to pass traffic to Internet behind corporate proxy.
Half of the solution:
To achive this, following works fine:
server {
listen 80;
server_name myhost.com;
location / {
proxy_set_header Host google.com;
proxy_pass http://corporateproxy:9999/;
}
}
However, above solution does not use SSL between corporate proxy and google.com. Do you have any idea how to add SSL to this?
I have tried adding protocol or port to header but it is not working this way.
I cannot modify anything on the corporate proxy. It should work like this: the URL being accessed is with https it will be redirected to https; http to http. Unfortunatelly header that contains only dns name is treated as http request.
Unfortunatelly the simplest solution does not work because nginx does not respect http_proxy settings on RedHat Machine:
server {
listen 80;
server_name myhost.com;
location / {
proxy_pass https://google.com/;
}
}
Any help will be highly appreciated.

Nginx serves different website (on the same sever) when using HTTPS

I have several websites hosted on the same sever. To simplify I have just 2 (http-only.com and https.com) and using nginx to handle requests.
One has SSL enabled. And another doesn't. I noticed links like this in Google Search Console http-only.com/https_server_path and when accessing an http-only.com server with https protocol I get requests served by an https.com server instead.
https.com:
server {
listen 443 ssl;
server_name https.com;
ssl on;
}
only-http.com:
server {
listen 80;
server_name only-http.com;
}
I think I should define something like a default ssl server to handle ssl for http.com, but don't know how to do it properly. I guess nginx should redirect https request to an http url if corresponding server doesn't handle https. Or maybe there is a better solution?

Nginx forward a URL to another URL:Port

I have a server that's using nginx and httpd (vestaCP). I'm trying to get panel.domain.com to go to domain.com:8083. I can't use proxy pass as changing the URL screws up vestacp. So i'm just needing nginx to forward people to domain.com:8083 when they go to panel.domain.com.
I currently have:
server {
listen 443;
server_name panel.domain.com.au;
return 301 https://domain.com.au:8083;
}