There are thousands of blogs and websites out there explaining how to do a hello world and how to start with VueJS, but in this
little post, I’m just going to be explaining how to do deploy a VueJs app after you have run the command through the
CLI npm run build.
little post, I’m just going to be explaining how to do deploy a VueJs app after you have run the command through the
CLI npm run build.
So when you run the command npm run build a dist folder is created and that folder’s got the
essential .js files to run our app, when we want to run our app on an Nginx server by default the vue-router is not going to work well
so that Nginx does not come ready to work by default with a VueJs app
essential .js files to run our app, when we want to run our app on an Nginx server by default the vue-router is not going to work well
so that Nginx does not come ready to work by default with a VueJs app
This is basically for a Linux Ubuntu distribution if you’ve got any other Linux distribution just pay attention where is going to be
set the www/html folder and the Nginx settings so that this is useful for any Linux distribution
set the www/html folder and the Nginx settings so that this is useful for any Linux distribution
Install and configure nginx
sudo apt install nginx
Double check to make sure the nginx service is running with command service nginx status, then open your browser and
enter url http://{server_ip}, you should see some welcome message from nginx. “replace server_ip by your ser ver ip address”
enter url http://{server_ip}, you should see some welcome message from nginx. “replace server_ip by your ser ver ip address”
Configure nginx
sudo touch /etc/nginx/sites-available/vue_project
sudo ln -s /etc/nginx/sites-available/vue_project /etc/nginx/sites-enabled/vue_project sudo vim /etc/nginx/sites-available/vue_project |
Sample configuration:
server {
listen 80; server_name example.com; charset utf-8; root {{app_root}}/dist; index index.html index.htm; # Always serve index.html for any request location / { root {{app_root}}/dist; try_files $uri /index.html; } error_log /var/log/nginx/vue-app-error.log; access_log /var/log/nginx/vue-app-access.log; } |
What I mean with this {{app_root}}/dist, is that you must replace what is inside {{}} and set the path where you’ve got your application, copy an paste the piece of code but replace what is inside of the {{}} with your path, in my case I just created a folder in /var/www/html/vuejs, and inside that folder I unzipped the vue folder app which I downloaded from GitHub and run npm run build, I did it with GitHub but you can upload to the server the files too with SCP or with any
other tools, it is up to you, if you do not have Nodejs and Npm on your Linux server just click on
step by step to set up a proper Nodejs and Npm for you.
Check configuration, then restart nginx:
sudo nginx -t
sudo service nginx restart |
Now, you should have your application up and running
Very informative - How to deploy a VueJS App using Nginx on Ubuntu (will try this...)
ReplyDeleteKeep posting..
VueJS Development Company
VueJS Development Services