Maven创建聚合工程和前后端部署

Maven创建聚合工程

在父工程中设置

<packaging>pom</packaging>

其他子工程中设置(api中不用设置)

<packaging>jar</packaging>

有Spring boot依赖的工程中包括:Maven build

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

后端项目部署:

1. 搭建云服务器环境(jdk, MySQL)

2. Maven聚合工程打包:

fmmall ---》 install

api ----》 package

生成的api.jar为最终的jar包

3. 上传到云服务器

4. 启动项目: java -jar api.jar & (后台)

Nginx在Window下的安装,配置,启动

1. Nginx安装

Nginx可以作为静态资源服务器;也可以作为代理服务器,负责负载均衡。

nginx: download

解压即可 ,运⾏nginx.exe。

nginx 默认端⼝ 80,所以直接访问 : http://localhost

2. Nginx配置

nginx.conf

#user nobody;
# 配置处理器个数(应不⼤于cpu核⼼数)
worker_processes 1;
# 配置nginx运⾏⽇志⽂件
error_log logs/error.log;
# 配置Nginx进程的进程号的存储⽂件
# pid logs/nginx.pid;
# 配置nginx连接数,数值越⼤并发能⼒越强
四、锋迷商城—前端部署
安装Nginx
将前端项⽬fmall-static拷⻉到nginx的根⽬录
修改nginx.conf:
events {
 worker_connections 2000;
}
http {
 include mime.types;
 default_type application/octet-stream;
 sendfile on;
 keepalive_timeout 65;
 server {
 # 配置nginx端⼝号
 listen 80;
 server_name localhost;
 # 地址映射
 #location / {
 # root html;
 # index index.html index.htm;
 #}
 location / {
 root fmall-static;
 index index.html index.htm;
 }
 # 指定错误⻚⾯
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root html;
 }
 
 }
}

Nginx在Linux下的安装,配置,启动

nginx: Linux packages

1. 安装编译⼯具(nginx安装之前需要编译)

# apt-get install -y gcc gcc-c++

2. 安装PCRE

# 1.下载
# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre8.35.tar.gz
# 2.解压
# tar -zxvf pcre-8.35.tar.gz
# 3.进⼊pcre⽬录
# cd pcre-8.35
# 4.配置
#./configure
# 5.编译安装
# make && make instal

3. 安装SSL库

# cd /usr/local
# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
# tar -zxvf openssl-1.0.1j.tar.gz
# cd openssl-1.0.1j
# ./config
# make && make install

4. 安装zlib库

# cd /usr/local
# wget http://zlib.net/zlib-1.2.11.tar.gz
# tar -zxvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure
# make && make install

5. 安装Nginx

# cd /usr/local
# wget http://nginx.org/download/nginx-1.16.1.tar.gz
# tar -zxvf nginx-1.16.1.tar.gz
# mkdir -p server/nginx
# cd nginx-1.16.1
# ./configure --prefix=/usr/local/server/nginx --withhttp_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35
# make && make install
# 如果在配置过程中出现了以下错误:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
# 执⾏:apt-get -y install openssl openssl-deve

6. 配置Nginx

vim /usr/local/server/nginx/conf/nginx.conf

7. 启动Nginx

在nginx目录下,执行sbin/nginx

 

前端项目部署(Nginx)

 打包

# npm run build

所有的.vue文件都被打包编译成了dist/static目录下,其中包括js, css, map和index.html。将其放到nginx服务器上。使用scp或ftp的方式,将代码上传到服务器。配置nginx的访问路径(地址映射)。

 

跨域请求的3种方式:

1. 后端设置响应数据允许跨域。(@CrossOrigin)

2. 前端采用JSONP的方式。该技术底层是基于script标签实现的,因为script标签是可以跨域的

3. 前端在build/config/index.js中,

proxyTable: {
  '/api': {
    target: 'http://siwei.me',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }
},

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值