I have an Nginx running in the front of a node js server (next.js). I'm trying to write my Nginx config in order to achieve this behavior, I want to add the hostname as the first part in the path before proxy_pass to node js.
for example, the client will write a.com/
or a.com/product/...
or a.com/**
.
my nextjs application except for something like http://a.com/[:domainname]/.... while the domain name is the same as the host.
so the goal is to change the URL from a.com/**
to a.com/a.com/**
, before passing that to nextjs server.
the nginx config i created :
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# if ($host = a.com) { proxy_pass http://site/a/; }
# if ($host = b.com) { proxy_pass http://site/b/; }
rewrite ^(/.*)$ /$host/$1 ;
proxy_pass http://site;
}
but that didn't work.