Instantly share code, notes, and snippets.

@kuntoaji /nginx.conf
Last active Aug 29, 2015

What would you like to do?
Nginx Load Balancer Configuration
# default nginx configuration
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/;
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;
include /etc/nginx/conf.d/*.conf;
# mulai dari sini :)
upstream mybackend {
# Weight adalah bobot yang digunakan seberapa sering backend server tersebut dipilih untuk memproses request.
# Default weight adalah 1
server weight=4;
server weight=2;
server unix:/tmp/backend4;
server {
listen 80;
location / {
proxy_pass http://mybackend;
# header ini digunakan agar backend app mengenal request domain sebagai atau, bukan sebagai mybackend
proxy_set_header Host $http_host;
# header ini digunakan agar IP yang diproses aplikasi backend berasal dari IP client, bukan dari load balancer.
proxy_set_header X-Real-IP $remote_addr;
# beberapa aplikasi atau framework menggunakan X-Forwarded-For untuk mendapatkan alamat IP.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment