vuejs打包部署到服务器上,可以选择tomcat或者nginx两种方式进行运行,我个人更倾向于用nginx,这里就讲述下使用nginx的配置。
1、进入到vuejs工程目录下执行以下语句打包:
npm run build
执行完在工程目录下多出一个dist文件夹,这下面就是打包好的文件
2、传到服务器某个路径下,并配置nginx.conf
#user nobody;
user root;
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8089;
server_name test;
#charset koi8-r;
#access_log logs/host.access.log main;
#配置前端vuejs包路径
location / {
root /home/devops/iview/dist;
index index.html index.htm;
#防止url转跳代#号
try_files $uri $uri/ /index.html;
}
#配置后台地址
location /test/ {
proxy_pass http://localhost:8080/test/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
/scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
参考:https://www.jianshu.com/p/348024b6b3ab