Skip to content

Instantly share code, notes, and snippets.

@rubenmoya
Created May 13, 2020 12:47
Show Gist options
  • Save rubenmoya/4a3b71c0edd05ad49a3017e201a54942 to your computer and use it in GitHub Desktop.
Save rubenmoya/4a3b71c0edd05ad49a3017e201a54942 to your computer and use it in GitHub Desktop.
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $upstream_addr '
'"$http_referer" "$http_user_agent"';
# Redirect 80 to 443
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
# Listen on 443
listen 443 ssl;
# Configure cets
ssl_certificate /path/to/certificates/something.crt;
ssl_certificate_key /path/to/certificates/something.key;
# domains, ips, etc
server_name mikel.com www.mikel.com;
# set the root folder
root /path/to/app;
access_log /path/to/app/log/nginx.access.log compression;
error_log /path/to/app/log/nginx.error.log info;
# what file to server as index
index index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to redirecting to index.html
try_files $uri $uri/ /index.html;
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# Javascript and CSS files
location ~* \.(?:css|js)$ {
try_files $uri =404;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# Any route containing a file extension (e.g. /devicesfile.js)
location ~ ^.+\..+$ {
try_files $uri =404;
}
location /api {
# all /api requests are proxied to the server
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_buffering off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment