My web app allows users to create their own profiles with custom usernames, which can be accessed via the following URLs.
ourplatform.com/john
ourplatform.com/john/about
ourplatform.com/john/contact
ourplatform.com/jane
ourplatform.com/jane/about
ourplatform.com/jane/contact
Users also have the option to link their domain names to their profiles, resulting in URLs structured like this.
john.com
john.com/about
john.com/contact
jane.com
jane.com/about
jane.com/contact
Here is an excerpt from my next.config.js
file.
module.exports = {
async rewrites () {
return [
{
source: '/:path*',
has: [
{
type: 'header',
key: 'x-username',
value: '(?<username>.*)'
}
],
destination: '/:username/:path*'
}
]
}
}
In addition, here is the relevant Nginx configuration.
server {
listen 80;
server_name john.com;
add_header x-username "john";
proxy_set_header x-username "john";
location /_next {
proxy_pass http://127.0.0.1:1323;
}
location = / {
proxy_pass http://127.0.0.1:1323/john;
}
location / {
proxy_pass http://127.0.0.1:1323/john$request_uri;
}
}
Despite these configurations, I am encountering a 404 error on the linked domains. Can anyone pinpoint what might be causing this issue?