Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alex-arriaga/b8e198c2617442abf8a53b8473a7d475 to your computer and use it in GitHub Desktop.
Save alex-arriaga/b8e198c2617442abf8a53b8473a7d475 to your computer and use it in GitHub Desktop.
worker_processes auto;
error_log stderr warn;
pid nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_min_length 256;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
# Don't send the nginx version number in error pages and server header
server_tokens off;
# Don't allow the browser to render the page inside an frame or iframe
# and avoid clickjacking http://en.wikipedia.org/wiki/Clickjacking
add_header X-Frame-Options "SAMEORIGIN";
# Disable content-type sniffing on some browsers
# https://www.owasp.org/index.php/List_of_useful_HTTP_headers
add_header X-Content-Type-Options nosniff;
# Enables the Cross-site scripting (XSS) filter built into most recent web browsers
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';
server {
listen 80 default_server;
root /usr/share/nginx/html;
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js|json)$ {
expires 1y;
access_log off;
}
location / {
try_files $uri $uri/ /index.html;
}
}
}
@alex-arriaga
Copy link
Author

alex-arriaga commented Jan 18, 2019

If you are using Docker to deploy your Angular application:

  1. Create a file for nginx configuration in <ANGULAR_APP_ROOT_DIR>/docker/nginx/nginx.conf and place the previous content in there.
  2. Use a Dockerfile such as this one: https://gist.github.com/alex-arriaga/c821da19ff05d775906c23fc0496e887 to copy this file into a valid nginx directory (when building the docker image)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment