Publish a site in a subfolder with traefik and Next JS

Viewed 294

I'm trying publish a website in a subfolder (exemple.com/sitename) usign Traefik.

The site is build with Next JS.

What is happening when I run deploy is that all script links in the builded site disregard the folder (sitename). For example, js script named generatedfile.js is being accessed by the link example.com/generatedfile.js, the corret way would be example.com/sitename/generatedfile.js

My traefik args:

-l traefik.frontend.rule="Host:example.com; PathPrefixStrip:/sitename" -l traefik.frontend.entryPoints="http, https" -l traefik.frontend.headers.SSLRedirect="true" 

I had tried add basePath to my next.config.js, but when I do this, I only access de site in the link exemple.com/sitename/sitename

next.config.js:

module.exports = withFonts({
  basePath: '/sitename'
});

I'm using docker to deploy in AWS.

I've been trying to solve this all day, I don't even know what else to try to solve it.

Sorry for my english, it's not my first language.

1 Answers

PathPrefixStrip means match the path and strip the matched string before forwarding the request to your application. Use PathPrefix instead.

Looks like you're using v1.x of Traefik. Here's the documentation explaining the difference better: https://doc.traefik.io/traefik/v1.7/basics/

It's worth mentioning that if you have multiple routing rules, Traefik sorts them by their string length in a descending order and goes through them to match the incoming request. In other words, /api is matched before /.

Related