springboot和vue两个前后端分离项目部署,前台使用的是nginx
首先后台打包部署
先双击clean,再package打包项目(由于是独立部署所以是jar包)
打包成功,jar包在D盘路径下(synergy-0.0.1-SNAPSHOT.jar文件)
部署到window sever 2012运行
登录EASY CONNECT连接远程桌面
把本地的synergy-0.0.1-SNAPSHOT.jar包复制到服务器上
使用cmd窗口( 路径一点要切换到jar包所在的文件夹路径)
使用命令 java - jar xxx (jar包的名称)
后台部署成功
前台项目打包部署
打包vue项目
新建终端,输入命令 npm run build ,然后打包成功
注意事项:
1.服务器上没有这个就会少静态样式
publicPath: ‘…/…/’
assetsPublicPath: ‘/’,//开发使用
使用Nginx部署前台(这里使用的版本是1.2.2)
把dist文件夹放到nginx的文件夹里
配置nginx,在conf文件夹下打开nginx.conf
nginx.conf文件配置内容如下
#user nobody;
worker_processes 1;
#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;
client_max_body_size 8M;
client_body_buffer_size 128k;
fastcgi_intercept_errors on;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080; #替换为监听服务器的端口号
server_name 127.0.0.1 #替换为监听服务器的ip地址
#添加头部信息
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#charset koi8-r;
#access_log logs/host.access.log main;
#这里与vue开发环境下的配置代理一样
#生产环境下的代理地址
location ^~ /api/{ #xx
proxy_pass http://127.0.0.1:8081/;
}
location ^~ /city/{ #xx
proxy_pass http://127.0.0.1:9000/;
}
location / {
root dist;
index index.html index.htm;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /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;
# }
#}
}
最后双击nginx.exe即可运行
到此前后台项目部署成功!