Skip to content

Instantly share code, notes, and snippets.

@nikitalpopov
Last active February 14, 2019 14:34
Show Gist options
  • Save nikitalpopov/884c7196ab0120f3077c05284e372114 to your computer and use it in GitHub Desktop.
Save nikitalpopov/884c7196ab0120f3077c05284e372114 to your computer and use it in GitHub Desktop.
nginx configuration file for node.js app
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
client_max_body_size 100m;
#keepalive_timeout 0;
keepalive_timeout 65;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
listen 4200;
server_name localhost;
location / {
root /dist;
try_files $uri $uri/ /index.html =404;
}
location /api {
rewrite ^\/api(.*)$ $1 break;
# requests to the API will be proxy_pass to the backend API infra
# read this -> http://en.wikipedia.org/wiki/X-Forwarded-For
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# pass the host header from the client to help with redirects
proxy_set_header Host $http_host;
# stops nginx from doing something silly
proxy_redirect off;
# proxy_pass to backend API
proxy_pass http://localhost:9901;
# send the IP address and remote server address for secuirty
proxy_set_header X-Real-IP $remote_addr;
}
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/geo+json
application/vnd.ms-fontobject
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
application/rdf+xml
font/otf
application/wasm
image/bmp
image/svg+xml
text/cache-manifest
text/css
text/javascript
text/plain
text/markdown
text/vcard
text/calendar
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
gzip_min_length 256;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment