Vue路由器和动态路由nginx

时间:2020-04-07 14:20:44

标签: vue.js nginx dynamic vue-router router

我一直在使用历史记录模式,该模式运行良好,并使用了简单的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;
}

}

router / 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

1 个答案:

答案 0 :(得分:0)

首先要证明的是,我需要添加到我的自定义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;
         }
 }