相关疑难解决方法(0)

vue-router、nginx 和直接链接

我正在尝试在我的 nginx 服务器上设置一个 vue-router。我遇到的问题是,如果我将 url 直接输入到浏览器,我的路线将不起作用myapp.com/mypath

我已经尝试过vue 路由器文档中描述的服务器配置以及关于堆栈溢出的建议类似配置。我当前的nginx位置配置如下:

location / {
    try_files $uri $uri/ /index.html;
}

location /subscribe {
    proxy_pass http://127.0.0.1/subscribe // express API app
}
Run Code Online (Sandbox Code Playgroud)

所做的只是将任何路径重定向到我的根组件(路径:)/而不是/mypath. 这确实有意义,并且location似乎只重定向到索引文件。我怎样才能重定向的直接链接myapp.com/mypath/mypath我的VueJS应用程序路径?

这是我现在的 vue 路由设置方式:

...
const routes = [
    { path: '/', component: Landing },
    { path: '/mypath', component: MyPath }
];

const router = new VueRouter({ mode: 'history', routes });

new Vue({
    el: '#app',
    router,
    render: h => …
Run Code Online (Sandbox Code Playgroud)

nginx vue.js vue-router vuejs2

7
推荐指数
2
解决办法
9913
查看次数

如何在 Docker 上为 Vue-router 配置 nginx

我正在设置一个 docker 图像,nginx以便将 Vue 应用程序作为静态文件提供服务。我的 vue 应用程序使用 Vue-Router,它可以在其他服务器上完美运行。我的 nginx 配置是这样的:https : //router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations

现在我想迁移到 docker,这是我的 Dockerfile

# build stage
FROM node:9.11.1-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:1.15.8-alpine as production-stage
COPY docker/nginx/prod.conf /etc/nginx/nginx.conf/prod.conf         # [*]
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Run Code Online (Sandbox Code Playgroud)

这是 docker/nginx/prod.conf

server {
  listen 80;
  server_name _ default_server;

  root /usr/share/nginx/html;

  location / {
    try_files $uri $uri/ …
Run Code Online (Sandbox Code Playgroud)

nginx docker vue-router

5
推荐指数
1
解决办法
5021
查看次数

标签 统计

nginx ×2

vue-router ×2

docker ×1

vue.js ×1

vuejs2 ×1