I have a section in my NGINX config file that uses proxy_pass
to redirect API traffic to upstream servers. I have the location
s in one server
block that serves both http and https requests:
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
server_name mysite.local; # Valid TLD in production
I then have location
blocks to define my API gateways:
location /api/v1/json {
# Various proxy config directives
proxy_pass http://upstream;
My question is: would it be possible to drop http://
and pass requests to my upstream servers depending on the protocol without splitting my server
block? Something like HTML/JavaScript //mysite.local
requests.
The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.
The PROXY protocol enables NGINX and NGINX Plus to receive client connection information passed through proxy servers and load balancers such as HAproxy and Amazon Elastic Load Balancer (ELB). With the PROXY protocol, NGINX can learn the originating IP address from HTTP, SSL, HTTP/2, SPDY, WebSocket, and TCP.
Security and anonymity – By intercepting requests headed for your backend servers, a reverse proxy server protects their identities and acts as an additional defense against security attacks.
NGINX was initially designed as a reverse proxy server. However, with continuous development, NGINX also serves as one of the options to implement the forward proxy. The forward proxy itself is not complex, the key issue it addresses is how to encrypt HTTPS traffic.
You could use the $scheme
variable:
location /api/v1/json {
# Various proxy config directives
proxy_pass $scheme://your-host
}
From the docs:
$scheme
request scheme, "http" or "https"
Which would then use the same protocol as the original request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With