[Vuejs]-Pushing the `dist` directory of a vue-cli project to a subfolder of an nginx server using git hooks

1👍

You’ll have to define a location block and specify the path to your dist folder. In your case, add this code insites_enabled/site_name.com.conf:

location /highlights {
    root path/to/your/app/dist;
}

0👍

There’s a very good page on the official Vue CLI docs that goes over common deployment strategies, that has a great example nginx config which I personally use in my apps: (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;
    }
  }
}

This has been working great for me. I just copy my dist folder to a directory called /app on my server. I personally do this with docker, which there’s a great example of on this page too.

Leave a comment