1 centos 安装java
官网下载java8 jdk :https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
选择x64 Compressed Archive
(1)mkdir /usr/local/java/ 创建目录
(2)tar -zxvf jdk-8u311-linux-x64.tar.gz -C /usr/local/java/ 解压缩
(3)设置环境变量
vi /etc/profile
添加:
export JAVA_HOME=/usr/local/java/jdk1.8.0_311
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
(4)source /etc/profile 使环境变量生效
(5)ln -s /usr/local/java/jdk1.8.0_311/bin/java /usr/bin/java 添加软链接
(6) java -version 验证是否安装成功
2,nohup java -jar test.jar > temp.txt & 后台运行springboot项目
3,nginx 反向代理java项目
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
4,其他
java项目本身端口号不对外开放,通过nginx代理访问。