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

  • 安装完后进入安装目录,如下:
    Springboot+vue+nginx部署到linux_第1张图片
  • 移动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即可访问。

你可能感兴趣的:(运维部署相关)