vue.js - Vue-router 和动态路由 nginx
问题描述
我一直在使用运行良好的历史模式并使用简单的 nginx。我现在添加了动态路由,以便当用户键入 baseurl.com/microcosm/anynametheywant - 这会将它们连接到在本地开发中非常有用的空间,但是当我移动到服务器时,我从中得到 404,我尝试了一个数字这里的东西是当前的 nginx,router/index.js - 仍然无法正常工作,仍然返回服务器 404,甚至组件帮助都不赞赏
NGINX 文件原样
server {
listen 111.111.11.111:80;
server_name *.nodenogg.in;
location / {
try_files $uri $uri/ /index.html;
}
location @rewrites {
rewrite ^(.)$ /index.html last;
}
location ~ /microcosm/\d+$ {
try_files $uri $uri/ /index.html;
}
}
路由器/index.js
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: () =>
import(/* webpackChunkName: "about" */ '../views/About.vue')
},
// dynamic segement `:microcosm` is added to the path
{
path: '/microcosm/:microcosm',
component: Home
},
{
path: '*',
name: 'NotFound',
component: NotFound
}
]
const router = new VueRouter({
mode: 'history',
base: base: process.env.VUE_APP_HTTP + '://' + process.env.VUE_APP_URL + '/',
routes
})
export default router
抓取和使用 Router.currentRoute.params.microcosm
解决方案
结果首先我需要添加到我的自定义 nginx 的底部,当然我需要在 443 上监听,所以它从来没有被听到,我什至不需要别名,因为我希望它是 404 和现在这是我的定制!最后然后删除 *.nodenogg.in 真是一个错误,花了我几个小时!
server {
listen 111.111.11.111:443 ssl;
server_name alpha.nodenogg.in ssl;
root /var/www/vhosts/nodenogg.in/alpha.nodenogg.in;
ssl_certificate /location/ofthekey/cert.pem;
ssl_certificate_key /location/ofthekey/privkey.pem;
ssl_protocols SSLv3;
location / {
try_files $uri $uri/ /index.html;
}
}
推荐阅读
- php - Codeigniter 支持 htaccess windows live server 和?
- javascript - Ionic 3 中断数据和显示或角度树干选项
- java - 访问在不同按钮中声明的对象参数
- html - 如何使用 Bootstrap 在页面上设计这些形状?
- c# - 是否可以从c#中的文本文件中获取指定字符串之后的字符串字符
- c# - 通用方法的成功/失败返回类型
- javascript - JavaScript:永远不会丢失绑定的方法
- javascript - javascript捕获一个输入
- javascript - 树形图 - 防止标签重叠节点
- javascript - 使用 Partial View、JQuery 和 Bootstrap Modal 编辑记录