server { # ssl and http2 in case of lets encrypt use listen 80 443 ssl http2; # your domain server_name domain.com; # static content directory root /root/app/public; # entry point for page renderer. Alias prop - absolute path to nuxt dir which contains prerendered nuxt pages. # If nginx found prerendered page, it reponses with it. If not - real time renderer responses. location / { alias /root/app/client/dist/$1; try_files $uri/index.html @renderer; } # proxy to nuxt real time renderer. location @renderer { proxy_pass http://localhost:3000; error_page 502 = /200.html; } # If renderer crashes, nuxt runs in SPA mode. location = /200.html { alias /root/acmd/client/dist/$1; try_files /200.html =500; } # entry point for API server location /api { proxy_pass http://localhost:3001; client_max_body_size 3m; } # entry point for SPA admin page (if you have one) location /admin { try_files /app/index.html =404; } # serve nuxt bundle with max cache life. Modify alias prop - absolute path to .nuxt dir location ~*_nuxt(.*)$ { alias /root/app/client/.nuxt/dist/$1; gzip on; gzip_comp_level 6; gzip_vary on; gzip_types text/css application/json application/javascript text/javascript application/x-font-ttf font/opentype; expires max; } # serve static content location ~* \.(js|jpg|jpeg|txt|png|css|ico|map)$ { gzip_static on; expires 30d; } # refirect from /path/ to /path rewrite ^/(.*)/$ /$1 permanent; } # redirect for domain aliases server { server_name www.domain.com; return 301 $scheme://domain.com$request_uri; } # placeholder if user requests your servers' IP. server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; server_name _; location / { try_files $uri =404; } }