小編給大家分享一下Docker中nginx如何安裝與配置掛載,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
創新互聯是專業的隴南網站建設公司,隴南接單;提供成都做網站、成都網站建設,網頁設計,網站設計,建網站,PHP網站建設等專業做網站服務;采用PHP框架,可快速的進行隴南網站開發網頁制作和功能擴展;專業做搜索引擎喜愛的網站,專業的做網站團隊,希望更多企業前來合作!在Docker下載Nginx鏡像
docker pull nginx docker images
創建掛載目錄
mkdir -p /data/nginx/{conf,conf.d,html,logs}
編寫nginx,conf配置文件,并放在文件夾中
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name 182.254.161.54; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://pic; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } upstream pic{ server 182.254.161.54:8088 weight=5; server 182.254.161.54:8089 weight=5; } }
啟動容器
復制代碼 代碼如下:
docker run --name mynginx -d -p 82:80 -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx
查看啟動的容器
docker ps
先前已經在Docker部署兩個tomcat,一個是8088端口,另一個是8089端口,并進入兩個容器里編寫了簡單的頁面
訪問8088端口
訪問8089端口
現在通過Nginx訪問兩個tomcat的內容,實現負載均衡的功能,出于區別,更能體現負載均衡的功能,兩個頁面的內容不一樣,但是訪問路徑都一樣,只是通過Nginx反向代理去輪換訪問
看完了這篇文章,相信你對“Docker中nginx如何安裝與配置掛載”有了一定的了解,如果想了解更多相關知識,歡迎關注創新互聯行業資訊頻道,感謝各位的閱讀!
當前題目:Docker中nginx如何安裝與配置掛載-創新互聯
轉載源于:http://newbst.com/article34/doogpe.html
成都網站建設公司_創新互聯,為您提供小程序開發、動態網站、全網營銷推廣、網站設計公司、網站營銷、Google
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯