Skip to content

Commit

Permalink
Add security headers
Browse files Browse the repository at this point in the history
  • Loading branch information
berrydenhartog committed Feb 2, 2025
1 parent 9635a1e commit f6fd8b8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN npm run build
FROM nginx:1.27.3

COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

Expand Down
22 changes: 22 additions & 0 deletions default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80;
server_name _;

location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ $uri.html /index.html;
}

add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Strict-Transport-Security "max-age=31536000" always;
add_header Referrer-Policy "no-referrer" always;
add_header Content-Security-Policy "default-src 'self';" always;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
39 changes: 39 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

server_tokens off;

client_max_body_size 1M;

gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_proxied any;
gzip_min_length 256;

include /etc/nginx/conf.d/*.conf;
}

0 comments on commit f6fd8b8

Please sign in to comment.