使用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"
阅读 12.7k
3 个回答
location @rewrites {
        rewrite ^(.+)$ /index.html last;
    }

这一段不需要吧

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;
    }
}
新手上路,请多包涵
server {
  listen 80 default_server;
  listen [::]:80 default_server;

  root /your/root/path;

  index index.html;

  server_name you.server.com;

  location / {
    try_files $uri $uri/ @rewrites;
  }

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

  location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    # Some basic cache-control for static files to be sent to the browser
    expires max;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  }

}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏