搭建 Java
开发环境
安装 JDK
JDK
是开发Java
程序必须安装的软件,我们查看一下 yum
源里面的 JDK
:
1 2 3 4
| yum list java*
# 或 yum list | grep jdk
|
1
| yum install java-1.8.0-openjdk* -y
|
- 安装完成后,查看是否安装成功(安装成功回显示jdk的版本号):
1 2 3 4
| [root@caoxianliang local] openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-b10) OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
|
安装Tomcat
下载Tomcat,并解压到指定目录中。
/usr/local/java-tomcat
(我的安装目录)
1 2 3
| cd /usr/local/java-tomcat tar zxvf apache-tomcat-9.0.10.tar.gz mv ./apache-tomcat-9.0.10/ /usr/local/tomcat9
|
1
| chmod -R 777 /usr/local/tomcat9/bin
|
1
| /usr/local/tomcat9/bin/startup.sh
|
- 修改
Nginx
配置 (/usr/local/nginx/conf/nginx.conf
)
1 2 3 4 5 6 7 8 9 10 11 12
| location ~ .+\.jsp($|/) { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 6 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| server { listen 80; server_name java.caoxl.com;
location /i/ { alias /usr/local/tomcat9/webapps/ROOT/; }
location / { proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://127.0.0.1:8080; }
error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { }
}
|
别忘了 service nginx restart
重启Nginx
访问: java.caoxl.com 即可看到
动静分离
1 2 3 4
| location ~ \.(html|js|css|gif|jpg|png|bmp|swf)$ { expires 30d; root /usr/local/tomcat9/webapps/ROOT; }
|
至此, JavaWeb
搭建完成, 最后说一句, PHP
是世界上最好的语言