使用Nginx部署Vue项目出错

时间:2018-07-02 14:59:31

标签: nginx vue.js vue-router

我的Nginx配置如下:

server {
    index index.html index.htm;
    server_name ***;
    root /home/u/depolyfile/deploy;
    listen 80;
    location / {
        try_files $uri $uri/ @rewrites;
    }

    location @rewrites {
        rewrite ^(.+)$ /index.html last;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}

和我的Vue-Router一样:

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import DefaultPage from '@/components/DefaultPage'

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '*',
      name: 'DefaultPage',
      component: DefaultPage
    }
  ]
})

和我的Nginx总是出现错误: 2018/07/02 14:26:01 [错误] 5#5:* 25重写或内部重定向周期,同时重定向到命名位置“ @rewrites”

我不知道该如何解决。有人可以帮我吗?

0 个答案:

没有答案