在linux中先安装好前面的JDK、Tomact、MySql、Redis、Nginx
上传文件到Nginx目录中: /usr/local/nginx
1 将后端项目 jar 包上传至服务器目录:/usr/local/nginx-demo,如下所示:
2 使用 xshell 连接服务器,进入目录:/usr/local/nginx-demo
命令:nohup java -jar nginx-demo-0.0.1-SNAPSHOT.jar >debug.log 2>&1 &
页5 使用 Postman 测试接口,接口地址:http://127.0.0.1:8080/nginx-demo/html/getTestInfo1
注意:接口地址中的 127.0.0.1 应更换为部署后端项目所在的服务器 IP 地址
1 进入到 Nginx 的配置目录:/usr/local/nginx/conf/
注意:服务器中的 Nginx 安装目录如果不是”/usr/local/nginx”,请更换相应的安装目录,以
① "listen 80":指定 Nginx 监听所有 IP 地址且端口号为 80 的请求。
② "location /nginx-demo/":反向代理后端服务。当 URL 路径匹配该 location 时,就会
反向代理到"http://127.0.0.1:8080"地址上,然后调用后端服务中对应的接口
注意:配置文件中 127.0.0.1 应更换为部署后端项目所在的服务器 IP 地址
proxy_pass http://127.0.0.1:8080;
}
命令:/usr/local/nginx/sbin/nginx
4 使用 Postman 测试接口,接口地址:http://127.0.0.1/nginx-demo/html/getTestInfo127.
注意:127.0.0.1 应更换为部署 Nginx 所在的服务器 IP 地址
1 前端项目上传至服务器目录:/usr/local/nginx/html。html 目录是 Nginx 默认解析的静态文
2 前端项目源码在《演示示例 1:项目素材部署》中提供,home.js 文件如下所示:
注意:127.0.0.1 应更换为部署后端项目所在的服务器 IP 地址
页3 进入到 Nginx 的配置目录:/usr/local/nginx/conf/
"location /test/":配置前端项目。当 URL 路径匹配该 location 时,会执行该 location 下
的代码。如果访问"http://127.0.0.1/test/",Nginx 服务器就会指向根目录下的
注意:配置文件中 127.0.0.1 应更换为部署后端项目所在的服务器 IP 地址
server {
listen 80;
server_name localhost;
location / {
root dist;
index index.html index.htm;
}
location /test {
alias /usr/local/nginx/test;
index home.html;
}
location /nginx-demo/ {
proxy_pass http://127.0.0.1:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
命令:/usr/local/nginx/sbin/nginx -s stop
命令:/usr/local/nginx/sbin/nginx
6 打开浏览器,访问地址:http://127.0.0.1/test/,如下所示即前端项目部署成功:
注意:127.0.0.1 应更换为安装 Nginx 的服务器地址
黑客小红往A网站的网站内容中注入了一些非法内容(代码,获取用户的信息,并且将数据提交至小红的服务器)
跨域安全策略: A->数据请求的地址不属于A网站而是B网站的,这时浏览器就禁止此请求完成
打包项目
命令:nohup java -jar est-web-0.0.1-SNAPSHOT.jar >debug.log 2>&1 &
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_pass http://192.168.74.124:8088/est/api;
}
命令:/usr/local/nginx/sbin/nginx -s stop