Skip to content

Instantly share code, notes, and snippets.

@eric-wu
Last active October 27, 2022 01:45
Show Gist options
  • Save eric-wu/8483112 to your computer and use it in GitHub Desktop.
Save eric-wu/8483112 to your computer and use it in GitHub Desktop.
Nginx reverse proxy set up behind a elastic load balancer and in front of a Play web app. Redirects http to https.
# This sets up a nginx reverse proxy behind a load balancer and in front of
# the Play web app. The setup is illustrated as the following:
#
# LB:80 ==> RP:80 ==> (Redirect to https)
# LB:443 ==> RP:8080 ==> Backend:9001
#
# LB -- Load Balancer
# RP -- Reverse Proxy
#
# IMPORTANT: Remove the line `include /etc/nginx/sites-enabled/*` from this config
#
http {
##
# Reverse proxy
##
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
upstream dashboard-backend {
server localhost:9001;
}
server {
listen 8080;
server_name dashboard.synapse.org;
location / {
proxy_pass http://dashboard-backend;
}
}
##
# Redirect http to https
##
server {
listen 80;
return 301 https://$host$request_uri;
}
}
@nlhuykhang
Copy link

Hi @eric-wu
I am a newbie in this kind of stuff. Could you have me to answer these questions?

  • What is reason to put Nginx servers behind another load balancer like ELB?
  • What is the purposes of Nginx servers in this case?
  • Isn't better to point ELB directly to application servers?

Thanks

@mjuopperi
Copy link

Nginx is used to redirect HTTP requests to HTTPS in this example.
In some web servers this is more difficult to achieve so you can use a lightweight server in front to handle that.

@rasgolla
Copy link

rasgolla commented Sep 7, 2017

Hi Bro,
I want to use your code in my environment ..
Please clarify where should I use elb ip address and my splunk ip/url server address. In you example which is elb name/ip and play web app ?
Also from where we are picking up these parmaters :
proxy_set_header X-Real-IP $remote_addr; -->
proxy_set_header X-Scheme $scheme; -->
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; -->
proxy_set_header Host $host; ->
Regards,

@ferarnoled
Copy link

Any idea why you have to set up proxy_buffering off;?
I had to do it on my server config because of some inconsistent issues but have no idea why it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment