Skip to content

Instantly share code, notes, and snippets.

@saintc0d3r
Last active August 29, 2015 14:06
Show Gist options
  • Save saintc0d3r/3da55c3adc9e14d59454 to your computer and use it in GitHub Desktop.
Save saintc0d3r/3da55c3adc9e14d59454 to your computer and use it in GitHub Desktop.
[NginX] How to reverse proxy your internal web application server(s) using Nginx
# This file is usually placed in this following path: /etc/nginx
user nginx;
#user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types image/gif image/png text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
include /etc/nginx/conf.d/*.conf;
}
# This file is usually placed in this following path: /etc/nginx/conf.d
# All requests to this nginx server would be load balanced to any server's IP addresses/domain names you write inside this block.
upstream your_application_upstream{
server 192.1.6.55:8087; # The IP address+Port / fqdn of your web application server (e.g. www.yourawesomeapp.com)
# add more web application server(s)'s IP/domain name here as you like.
}
server {
listen 80;
server_name my.nginx-reverse-proxy.io nginx-reverse-proxy.io;
location /{
proxy_pass http://your_application_upstream; # notice that the value of this property points to the upstream block's name.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
# Avoiding '503 Gateway timeout', pretty useful when you're debugging the web application(s) behind nginx.
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
# proxy_redirect off;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header Host $host;
# proxy_set_header X-NginX-Proxy true;
# proxy_set_header Connection "";
# ..and other tons of settings..
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment