Springboot+vue+nginx部署到linux

1.部署环境准备

  • nginx安装包
    • 这里使用的编译好的nginx的安装包。
  • SpringBoot项目的jar包(接口服务)
    • demo.jar
  • vue项目打包
    • index.html
    • static文件夹
  • 服务器
    • centos7.x服务器或者虚拟机

2.运行Springboot服务

  • 服务器安装好jdk环境
  • Springboot项目jar包的application:配置
    server.servlet.context-path=/merge
    server.port=9890
  • 运行服务
    nohup java -jar demo.jar 2>&1 &

3.安装配置nginx

  • 安装完后进入安装目录,如下:
    在这里插入图片描述
  • 移动vue项目包到nginx里面
    • cd html
    • rm -rf *
    • 把 vue项目的index.html和static文件夹移动到这里
  • 配置nginx.conf
    • cd conf
    • vim nginx.conf
user  nobody;
worker_processes  2;
error_log  logs/error.log;
pid        logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
    worker_connections  10240;
    use epoll;
}                                    
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr $remote_port [$http_x_forwarded_for] [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" -- "$http_cookie" ["$upstream_addr" "$request_body" - $http_if_unmodified_since - $http_if_modified_since]'
                      '["$request_time" "$upstream_response_time" "$upstream_addr"] '
                      '"$http_cookie"';
    
    access_log  logs/access.log main;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    #keepalive_timeout  0;
    keepalive_timeout  300;

    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types  text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    #代理转发
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout 60;  
    proxy_send_timeout 60;  
    proxy_read_timeout 60;  

    server_names_hash_bucket_size  128;
    #客户端请求标头的缓冲区大小
    client_header_buffer_size		4k;
    client_max_body_size	50m; 
    #include    conf.d/servers.conf; 

# 核心配置
server {
	listen 9005;
	server_name localhost;
	location / {
		root html;
		index index.html index.htm;
	}
	location /merge{
		proxy_pass http://localhost:9890/merge;
	}
}
  • 启动nginx
    • cd sbin
    • ./nginx

4.访问

  • 登陆服务器ip:9005即可访问。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值