To access a path like /var/www/blog/
with a URI like /discover/
, you will need to use alias
rather than root
.
server {
server_name xyz.com www.xyz.com;
#root /var/www/html/folder_name;
#index index.html index.htm index.nginx-debian.html;
location /_next/static/ {
alias /var/www/project_folder/.next/static/; # !!! – change to your app name
expires 365d;
access_log off;
}
location / {
proxy_pass http://localhost:3000;
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;
}
# Handle PHP requests for /blog
location ^~ /blog {
alias /var/www/blog;
index index.php;
if (!-e $request_filename) { rewrite ^ /blog/index.php last; }
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; # Adjust PHP version if necessary
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
#listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
# ssl configuration;
ssl_certificate /etc/letsencrypt/live/xyz.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xyz.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = xyz.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name xyz.com www.xyz.com;
listen 80;
return 404; # managed by Certbot
}