• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

367
Views
Nginx, nuxt.js static generated mode and redirection of trailing slashs

i currently have a problem configuring my Nginx correctly for nuxt.js generated sites. What i want to achieve is the following

/magazin -> /magazin/index.html
/magazin/ -> 301 /magazin

/magazin/artikel/titel-goes-here -> /magazin/artikel/titel-goes-here/index.html
/magazin/artikel/titel-goes-here/ -> 301 /magazin/artikel/titel-goes-here

currently this is the other way around.

If im correct i shouldn't use a proxy pass to a e.g. pm2 instance with express etc. as it destroys the sense of static site generation.

But how can i get this page structure to work, as i need the same url's as our legacy service for SEO reasons, which used Angular Universal SSR

my current config is:

location ^~ /magazin {
   root /path/to/dist;
   index index.html ;
}

if i add something like

rewrite ^(.+)/+$ $1 permanent; 

i get an infinite 301 loop

Thanks for the help

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

You cannot use the built in index directive, as it works the other way around (as you have observed).

You can use try_files to test for the existence of the index.html file. Use a named location to process the redirection.

For example:

location ^~ /magazin {
    root /path/to/dist;
    try_files $uri $uri/index.html @rewrite;
}
location @rewrite {
    rewrite ^(.+)/$ $1 permanent;
}

See this document for details.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error