鍍金池/ 問答/Linux  HTML/ 使用nginx部署vue項目一直報錯

使用nginx部署vue項目一直報錯

使用nginx部署vue項目一直報錯,這個折騰我好幾天了,哪位大神知道是什么原因嗎?
下面是我的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 [error] 5#5: *25 rewrite or internal redirection cycle while redirect to named location "@rewrites"
回答
編輯回答
青裙

H5路由這樣就行 try_files $uri $uri/ /index.html =404;

server {
    listen 80;
    server_name xxx.cn;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    
    location / {
        root /home/u/depolyfile/deploy;
        index index.html index.php index.htm;
        try_files $uri $uri/ /index.html =404;
    }
    
    error_page 500 502 503 504 /50x.html;
    
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    
    location ~ /\.ht {
        deny all;
    }
}
2017年1月17日 09:25
編輯回答
氕氘氚
location @rewrites {
        rewrite ^(.+)$ /index.html last;
    }

這一段不需要吧

2017年8月2日 11:08