-
Describe the bugRecently, I deployed a document site on my server through Nginx and found that if I directly access the specified route, it will be forwarded to the homepage, but the routing address is the one that was accessed. At this point, clicking on other navigation options on the page would be confusing. And I have deployed a site on GitHub without experiencing this issue. I suspect it is a Nginx configuration issue. Can you help me take a look at the problem? Reproduction1.pnpm build Expected behaviorExpect normal routing access. System InfoSystem:
OS: Windows 10 10.0.19045
CPU: (24) x64 13th Gen Intel(R) Core(TM) i7-13700K
Memory: 21.30 GB / 31.75 GB
Binaries:
Node: 18.16.0 - D:\Develop\nodejs\node.EXE
npm: 9.5.1 - D:\Develop\nodejs\npm.CMD
pnpm: 8.6.12 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (115.0.1901.203)
Internet Explorer: 11.0.19041.1566 Additional contextN/A Validations
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 14 replies
-
Please use Discord or GitHub Discussions for a question 👍 And when you do, don't forget to paste your Nginx config so that people can see what's wrong with it 👀 |
Beta Was this translation helpful? Give feedback.
-
I have preliminarily resolved this issue by configuring cleanUrls to true in vitepress, the article directory structure of my project does not meet the corresponding requirements. Now I have removed this configuration, which means changing from |
Beta Was this translation helpful? Give feedback.
-
Do you have any other good solutions or configurations? Welcome to share them? |
Beta Was this translation helpful? Give feedback.
-
nginx加这个,匹配的路径 |
Beta Was this translation helpful? Give feedback.
-
Edit: I published a blog post about this 👇. Hi! I’m only starting with Vitepress, but here’s how I solved it with Nginx:
location / {
# defines which custom page to serve for 404 status code
error_page 404 /404.html;
# if `foo/bar` nor `foo/bar.html` nor `foo/bar/index.html` can’t work, answer with 404
try_files $uri $uri.html $uri/ =404;
} This has been tested on the following files structure.
server {
# many things here…
# remove trailing slash
rewrite ^(.+)/+$ $1 permanent;
location / {
# defines which custom page to serve for 404 status code
error_page 404 /404.html;
# if `foo/bar` nor `foo/bar.html` nor `foor/bar/index.html` can’t work, answer with 404
try_files $uri $uri.html $uri/ =404;
}
} Note that the Well, I think this is gonna be my first article on my blog using Vitepress. 😄 I’ll probably also PR this for the Vitepress deploy guide. |
Beta Was this translation helpful? Give feedback.
nginx加这个,匹配的路径
/docs/
改成你的location /docs/ { index index.html index.htm; try_files $uri $uri.html $uri/ /index.html; }