Nginx - How to Setup Web Site with Single Page Application(SPA)?
When you serve a web site in SPA, you will get 404 after F5 refresh page.
For example: We want to access a url http://127.0.0.1:8080/taiwan
1. Modified Web Vue Project Code
router.js
new VueRouter({
mode: 'history',
base: '/taiwan',
...
)}
webpack.config.js
...
output: {
...
publicPath: '/taiwan'
},
...
2. Modified Nginx Configuration
location /taiwan {
alias /usr/share/nginx/html/taiwan/;
try_files $uri $uri/ /taiwan/index.html;
index index.html;
}
3. Nginx Reload
# nginx -s reload
router.js
new VueRouter({
mode: 'history',
base: '/taiwan',
...
)}
webpack.config.js
...
output: {
...
publicPath: '/taiwan'
},
...
location /taiwan {
alias /usr/share/nginx/html/taiwan/;
try_files $uri $uri/ /taiwan/index.html;
index index.html;
}
3. Nginx Reload
# nginx -s reload
# nginx -s reload
Author And Source
この問題について(Nginx - How to Setup Web Site with Single Page Application(SPA)?), 我々は、より多くの情報をここで見つけました https://qiita.com/moonlightbox/items/49e3b71298f244f7ee78著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .