How can I create a proxy between two server? - api

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
}
}

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.

Reverse proxy to direct different name to different ports

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;
}
}

How to specify multiple server names in proxy_ssl_name in nginx reverse proxy configuration

My nginx upstream has multiple servers, eg:
upstream backend {
server backend1.example.com:12345;
server backend2.example.com:12345;
server anotherbackend.com:12345;
}
server {
listen 12345;
proxy_pass backend;
proxy_ssl on;
proxy_ssl_verify on;
proxy_ssl_name ??
The proxied HTTPS server can provide certificates with any of the subject names backend1.example.com or anotherbackend.com. Is it possible to configure the proxy_ssl_name to verify certificate with any of these subject names? Or do all the backend servers have to present the same certificate?
If you have corresponding certificate for every server, you can use
proxy_ssl_name $proxy_host;
Or can create one certificate with all Subjec Alt Name inside and distribute it to all backends

Difference HTTP Redirect vs Reverse Proxy in NGINX

I'm having some difficulty in understanding the difference between reverse proxy (i.e. using proxy_pass directive with a given upstream server) and a 301 permanent redirect. How are they similar/different?
Reverse Proxy
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
}
server {
location / {
proxy_pass http://backend;
}
}
HHTP Redirect
Apache Example: http://www.inmotionhosting.com/support/website/htaccess/redirect-without-changing-url
NGINX example:
server {
listen 80;
server_name domain1.com;
return 301 $scheme://domain2.com$request_uri;
}
Hence, it seems that both approaches have no difference from an end-user perspective. I want to ensure efficient bandwidth usage, while utilizing SSL. Currently, the app server uses its own self-signed SSL certificate with Nginx. What is the recommended approach for redirecting users from a website hosted by a standard web hosting company (hostgator, godaddy, etc.) to a separate server app server?
With a redirect the server tells the client to look elsewhere for the resource. The client will be aware of this new location. The new location must be reachable from the client.
A reverse proxy instead forwards the request of the client to some other location itself and sends the response from this location back to the client. This means that the client is not aware of the new location and that the new location does not need to be directly reachable by the client.

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?