Reverse proxy to direct different name to different ports - apache

We have 2 DNS names (call them D1 and D2) pointing to the same IP address (call it A). At A there are 2 webservers on different ports (say 8081 and 8082). I need to configure that the 2 names point to the 2 webservers eg D1 points A:8081 and D2 pints to A:8082. I think this is simple but have not been able to work out how to configure Apache or Nginx as reverse-proxy to do this. (This is just so users don't have to type a port number.)

You have two DNS names, so that will be implemented in Nginx as two server blocks with different server_name statements. See this document for details.
For example:
server {
server_name d1.example.com;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
server {
server_name d2.example.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}

Related

How can I create a proxy between two server?

I need to talk to server A.
but I have one authorized server B.
I need to create an Nginx file conf to proxy the requests from clients to server B, send the request from server B to server A, and get the response from server B to the client.
I have tried this conf:
server {
listen 80;
server_name a.aaa.com;
location /api/v2.0/product/detail.php {
proxy_pass https://bb.bbb.com
}
}

Nginx Reverse proxy translate domain to ip

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

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 let nginx do SSL pass-through for multiple virtual hosts?

I have multiple local https servers running on different ports with their own certificate. Now, I would like to use nginx to make these https servers available under different host names, port 443 and ssl secured.
My current configuration per hostname looks like
server {
listen 443 ssl;
server_name hostname1;
ssl_certificate /etc/nginx/hostname1.cert.pem;
ssl_certificate_key /etc/nginx/hostname1.privkey.pem;
location / {
proxy_pass ...
}
}
But using the listen 443 ssl; directive forces me to specify certificate and key. Instead, I would like to simply pass-through that traffic from my servers, so I do not have to maintain a second level of certificates in nginx and my local environment comes closer to the production environment.
For targeting a single server, F.X. offers a solution with streams in SSL Pass-Through in Nginx Reverse proxy?
However, as he/her points out, as it simply forwards TCP, there is no way to peek into the hostname and make it work for multiple servers.
Are there any other ways?
Is there some fundamental limitation that this cannot work?
The magic concept here is Server Name Indication, a TSL extensions which adds the host name desired by the client in the TSL Client Hello and allows the server to map the connection to one of multiple virtual hosts.
It turns out that the answer by F.X. was outdated and Dave T. has a solution
using two newer nginx modules, ngx_stream_ssl_preread and ngx_stream_map. See his answer on this network for details.

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.