Skip to content

Instantly share code, notes, and snippets.

@PatrickHeneise
Last active August 26, 2020 14:28
Show Gist options
  • Save PatrickHeneise/62dd5f4de838d20f4d2f647bc4b39474 to your computer and use it in GitHub Desktop.
Save PatrickHeneise/62dd5f4de838d20f4d2f647bc4b39474 to your computer and use it in GitHub Desktop.
nginx config for nuxt/node in compose, with ssl and path rewrite
events {
worker_connections 1024;
}
http {
upstream frontend {
# run web container on port 5000
server web:5000;
}
upstream api {
# run api container on port 3000
server api:3000;
}
server {
listen 8080 ssl;
resolver 127.0.0.11;
server_name localhost;
access_log off;
# add ssl certs
ssl_certificate /usr/share/certs/localhost+1.pem;
ssl_certificate_key /usr/share/certs/localhost+1-key.pem;
ssl_protocols TLSv1.2;
charset UTF-8;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
server_tokens off;
client_max_body_size 100M;
location / {
# proxy requests to https://localhost:8080 to web container
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://frontend;
}
location /api {
# proxy requests to https://localhost:8080/api to api container
rewrite ^/api/(.*) /$1? break;
proxy_pass http://api/;
}
location /assets {
# load assets requested by https://localhost:8080/assets
rewrite ^/assets/(.*) /$1? break;
include /etc/nginx/mime.types;
autoindex on;
root /usr/src/app/assets/;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment