我想使用 Nginx 作为我的网络服务器和我自己的 Dropwiward REST API,使用 Vue.js 构建一个单页应用程序。此外,我使用 Axios 来调用我的 REST 请求。
我的 nginx 配置看起来像
server {
listen 80;
server_name localhost;
location / {
root path/to/vue.js/Project;
index index.html index.htm;
include /etc/nginx/mime.types;
}
location /api/ {
rewrite ^/api^/ /$1 break;
proxy_pass http://localhost:8080/;
}
}
目前我只能调用我的 localhost/api/path/to/rescource
从后端获取信息。
我使用 HTML 和 javascript(vue.js) 构建了前端,到目前为止它已经运行良好。但是,当我想构建单页应用程序时,大多数教程都会提到 node.js。我怎样才能改用 Nginx?
最佳答案
将以下代码添加到您的 Nginx 配置中,如 VueRouter 文档中所述,here :
location / {
try_files $uri $uri/ /index.html;
}
此外,您需要在 VueRouter 上启用历史记录模式:
const router = new VueRouter({
mode: 'history',
routes: [...]
})
关于nginx - 如何将 vue.js 与 Nginx 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47655869/