【问题标题】:Pushing the `dist` directory of a vue-cli project to a subfolder of an nginx server using git hooks使用 git hooks 将 vue-cli 项目的 dist 目录推送到 nginx 服务器的子文件夹
【发布时间】:2019-10-12 21:33:25
【问题描述】:
我用 vue-cli 创建了一个 Vue 项目。我的生产代码在本地构建到 dist 文件夹。目前,当我提交该代码并将其推送到其来源时,会设置一个接收后挂钩,以将该 dist 文件夹的内容部署到服务器的根目录 - http://site_name.com。我想要做的是让dist 文件夹转到服务器的子文件夹http://site_name.com/highlights。我该怎么做?
【问题讨论】:
标签:
git
vue.js
nginx
githooks
vue-cli
【解决方案1】:
您必须定义一个 location 块并指定 dist 文件夹的路径。在您的情况下,将此代码添加到sites_enabled/site_name.com.conf:
location /highlights {
root path/to/your/app/dist;
}
【解决方案2】:
Vue CLI 官方文档上有一个非常好的页面,介绍了常见的部署策略,其中有一个很好的示例 nginx 配置,我个人在我的应用程序中使用它:(https://cli.vuejs.org/guide/deployment.html#docker-nginx)
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
这对我来说非常有用。我只是将我的 dist 文件夹复制到服务器上名为 /app 的目录中。我个人用 docker 来做这件事,这个页面上也有一个很好的例子。