Skip to content

Instantly share code, notes, and snippets.

@davidep87
Created April 28, 2017 16:33
Show Gist options
  • Save davidep87/022f18d4a4815f113cd4b50c0cbda4af to your computer and use it in GitHub Desktop.
Save davidep87/022f18d4a4815f113cd4b50c0cbda4af to your computer and use it in GitHub Desktop.
Nginx conf as reverse proxy for a nodejs app
#Replace /usr/local/etc/nginx/nginx.conf with this. This is the
# default location for Nginx according to 'nginx -h'
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
# This should be in the same directory as this conf
# e.g. /usr/local/etc/nginx
include mime.types;
default_type application/octet-stream;
# Note this log_format is named 'main', and is used with the access log below
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
listen 80;
server_name localhost;
access_log /usr/local/var/log/nginx/nodeApp.access.log main;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme; #http pr https
proxy_set_header X-Real-IP $remote_addr;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
root /path/of/your/project/build/;
index index.html index.htm;
}
location /api {
proxy_pass http://localhost:1337/api;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf)$ {
root /path/of/your/project/public/;
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location /build/ {
alias /path/of/your/project/build/;
expires 30d;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment