I want a proper nginx configuration for my next.js project which is a plattform with multiple users and the possibility to post ads. My question is if this block for serving static files is correct
location /_next/static/ {
alias /var/www/esfaras/.next/static/;
expires 365d;
access_log off;
}
Is the expires value good to odd? I am using getstaticprops and no ssr on the pages i count on being "static".
Is there any difference in this proxy pass
location / {
proxy_pass http://127.0.0.1:3000; #
...
}
or writing the value like this
http://localhost:3000
?
Can you detect any flaws or optimisation concerns in the full config below
Here is my full nginx config
server {
listen 80;
server_name esfaras.de www.esfaras.de;
return 301 https://www.esfaras.de$request_uri;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl;
server_name esfaras.de;
ssl_certificate /etc/letsencrypt/live/esfaras.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/esfaras.de/privkey.pem;
return 301 https://www.esfaras.de$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
listen 80;
server_name www.esfaras.de;
gzip on;
gzip_proxied any;
gzip_types application/javascript application/x-javascript text/css text/javascript;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_min_length 256;
location /_next/static/ {
alias /var/www/esfaras/.next/static/;
expires 365d;
access_log off;
}
location / {
proxy_pass http://127.0.0.1:3000; # Change to 3001 for the second app, but make sure the second Next.js app starts on port 3001.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# SSL certificate configurations (managed by Certbot)
ssl_certificate /etc/letsencrypt/live/www.esfaras.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.esfaras.de/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}