运行成功:
4、nginx发布前端项目
①、进入nginx文件:
进入conf.d文件夹, 查看default.conf文件:
server {
listen 80;
server_name www.zking.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
#首页配置
location / {
root /usr/local/tools/vue;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/htm l;
}
proxy the PHP scripts to Apache listening on 127.0.0.1:80
location ~^/spa/{
proxy_pass http://192.168.218.130:8080;
}
pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
#}
deny access to .htaccess files, if Apache’s document root
concurs with nginx’s one
#location ~ /.ht {
deny all;
#}
}
**②、将default.conf文件配置到nginx容器,**配置nginx环境
改容器里的配置不能点击虚拟机的文件进行修改,需使用vim编辑器,我未装vim↓
我们将配置文件拉到宿主机里,使用目录挂载,将配置文件挂载到容器。
新建nginx目录,进人nginx文件:
将配置文件、前端项目(静态源码)、日志文件丢到容器里运行:
配置文件:
server {
listen 80;
server_name www.zking.com;
location / {
root /etc/nginx/html/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
#location ~^/api/ {
# rewrite ^/api/(.*)$ /$1 break;
# proxy_pass http://tomcatList;
# proxy_redirect default;
}
location ~^/api/ {
proxy_pass http://192.168.218.130:8081;
}
}
监听域名,进入火绒修改:
前端项目(静态源码):
将此文件进行解压:
unzip vue.zip
目录挂载:
docker run -itd \ ——》后台运行
–name nginx01 \ ——》服务器名字
-v /home/nginx/conf.d:/etc/nginx/conf.d \ ——》目录挂载:冒号前面是你要挂载的资源,冒号后是要挂载到哪去
-v /home/nginx/html:/etc/nginx/html \
-v /home/nginx/log:/usr/log/nginx \
-p 8080:80 \
nginx
docker run -itd \
–name nginx01 \
-v /home/nginx/conf.d:/etc/nginx/conf.d \
-v /home/nginx/html:/etc/nginx/html \
-v /home/nginx/log:/usr/log/nginx \
-p 8080:80 \
nginx
运行:
5、反向代理
使后台访问不是访问虚拟机,而是访问后台
自定义容器:docker run -it --name spring01 -p 8081:8081 spring:2.0
查看spring01的镜像,根据网桥的地址修改default.conf文件
文件修改了,但nginx不会跟着变动,需要更新数据:docker exec -it nginx01 bash ——》
nginx -s reload
5、nginx实现负载均衡
default.conf文件:
#服务器的集群
upstream tomcatList { #服务器集群名字
server 172.17.0.3:8081 weight=1;
}
server {
listen 80;
server_name www.zking.com;
location / {
root /etc/nginx/html/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~^/api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://tomcatList;
proxy_redirect default;
}
}
查看负载均衡轮回
再新建一个容器:
docker run -it --name spring02 -p 8082:8081 spring:2.0
default.conf文件:
浏览器多次访问,两个服务呈现结果:
最后
按照上面的过程,4个月的时间刚刚好。当然Java的体系是很庞大的,还有很多更高级的技能需要掌握,但不要着急,这些完全可以放到以后工作中边用别学。
学习编程就是一个由混沌到有序的过程,所以你在学习过程中,如果一时碰到理解不了的知识点,大可不必沮丧,更不要气馁,这都是正常的不能再正常的事情了,不过是“人同此心,心同此理”的暂时而已。
“道路是曲折的,前途是光明的!”
必看视频!获取2024年最新Java开发全套学习资料 备注Java
有很多更高级的技能需要掌握,但不要着急,这些完全可以放到以后工作中边用别学。
学习编程就是一个由混沌到有序的过程,所以你在学习过程中,如果一时碰到理解不了的知识点,大可不必沮丧,更不要气馁,这都是正常的不能再正常的事情了,不过是“人同此心,心同此理”的暂时而已。
“道路是曲折的,前途是光明的!”
[外链图片转存中…(img-o8DRvCce-1716407758575)]
[外链图片转存中…(img-CmVPIkRf-1716407758576)]
必看视频!获取2024年最新Java开发全套学习资料 备注Java