Nginx
1.Nginx反向代理:
1.Docker下載nginx鏡像
注意:nginx的掛載比較特殊:
需要先運行起來,然后把容器內的配置文件拷貝到當前的目錄,關閉並移除nginx,重新運行並掛載目錄文件。
1.運行nginx,沒有則自動下載
docker run -p 8090:80 --name nginx -d nginx
2.將容器內的配置文件拷貝到當前目錄:
docker container cp nginx:/etc/nginx .
3.修改nginx 名稱為conf,並創建新的nginx文件
mv nginx conf
4.移動conf到nginx/ 目錄
mv conf nginx/
5.重新運行nginx
docker run -p 8090:80 --name nginx \
-v ~/mydata/nginx/html:/usr/share/nginx/html \
-v ~/mydata/nginx/conf:/etc/nginx \
-v ~/mydata/nginx/logs:/var/log/nginx \
-d nginx
2.測試nginx反向代理
1.在html文件夾下創建 index.html
文件,注意一是 index.html
文件。因為default.conf文件下配置的為index.html,若要改成a.html則需要修改文件並重啟nginx服務。
2.寫上內容,並打開瀏覽器訪問 http://localhost:8090/
進行測試。
3.Nginx部署多個springboot項目
https://blog.csdn.net/weixin_35688029/article/details/81773300
2.Nginx負載均衡
1.首先在nginx.conf文件的http中添加:
upstream myserver{
server 本機ip:8080 weight=1;
server 本機ip:8081 weight=1;
}
2.在location中添加:
location / {
proxy_pass http://myserver;
}
3.Nginx中文網站
https://www.nginx.cn/doc/example/loadbanlance.html