<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                #### 1. 前提是Docker已經安裝好了 > 沒有安裝的可以看這篇文章-->[# centos7安裝docker](http://kanclouds.roes.top/linux/1592928) #### 2.拉取Nginx鏡像 ```shell docker pull nginx #使用命令查看拉取到的鏡像 docker images ``` ![image.png](https://upload-images.jianshu.io/upload_images/7100414-5b458e63101b1829.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) #### 3. 運行Nginx鏡像 ```shell docker run -d -p 80:80 --name nginx nginx ``` 參數說明 - ```-d``` 以守護模式運行鏡像,也就是后臺運行 - ```-p``` 宿主機端口映射的鏡像端口,左邊是宿主機端口,右邊是鏡像端口,```80```是Nginx訪問端口 - ```--name```給容器起一個唯一的別名 啟動后輸入```docker ps -a```即可查看運行的容器: ![image.png](https://upload-images.jianshu.io/upload_images/7100414-7afe7820908b9b4f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) #### 4. 訪問Nginx 瀏覽器訪問```http://ip```即可,出現以下頁面說明運行成功 ![image.png](https://upload-images.jianshu.io/upload_images/7100414-9fa5415f42474bb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) #### 5. 配置Nginx * 我們首先需要在宿主機創建用于存放nginx日志、配置文件和相關靜態資源的目錄,并將其掛載到容器內對應路徑。 * 后續更新我們只需要更改宿主機目錄下的配置文件或者靜態文件就可以更新容器內資源,這樣可以確保容器掛掉只需要重新啟動一個容器掛載上數據去就完美無缺的還原,這也是容器輕量快速方便的原因。不只是nginx容器,其余的像mysql容器也一定要記得掛載/data數據文件,防止容器宕掉丟失數據。 ```shell mkdir -p /home/service/nginx/log mkdir -p /home/service/nginx/conf mkdir -p /home/service/nginx/conf.d mkdir -p /home/service/nginx/static mkdir -p /home/service/nginx/ssl ``` 然后從Nginx容器中復制一份配置文件到宿主機剛剛創建的conf目錄 ```shell docker cp nginx:/etc/nginx/nginx.conf /home/service/nginx/conf/nginx.conf ``` 可以看到已經有了 ![image.png](https://upload-images.jianshu.io/upload_images/7100414-ca7a9b7741a1e5c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 查看一下內容 ![image.png](https://upload-images.jianshu.io/upload_images/7100414-ab8cf1d95c3aed82.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 上圖可以看出,這個配置文件還引入了其他的配置文件,所以我們需要把```include```引入的文件也復制一份到宿主機,但是我們不知道那些文件叫什么,所以我們需要進入容器內查看 ```shell docker exec -it nginx /bin/bash cd /etc/nginx/conf.d ls ``` 可以看到里面有個default.conf文件 ![image.png](https://upload-images.jianshu.io/upload_images/7100414-e884341bfed498c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 我們需要把這個文件復制到宿主機,使用```exit```命令退出容器 ```shell exit docker cp nginx:/etc/nginx/conf.d/default.conf /home/service/nginx/conf.d/default.conf ``` 還記得我們前面訪問nginx的時候那個頁面嗎?是的,那個頁面也要復制到宿主機 ```shell docker cp nginx:/usr/share/nginx/html/index.html /home/service/nginx/static/index.html ``` #### 6. 修改配置文件 開始修改宿主機上復制出來的conf文件,首先修改```nginx.conf```,修改配置文件修改后的結果: ```nginx user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include /etc/nginx/mime.types; default_type application/octet-stream; charset utf-8; keepalive_timeout 60; 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; server { listen 80; server_name www.roes.top; location / { root /usr/share/nginx/html; index index.html index.htm; } } include /etc/nginx/conf.d/*.conf; } ``` 查看```default.conf``` ```nginx server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } ``` ##### 停止上次的nginx容器并刪除容器 ```shell docker stop nginx docker rm nginx ``` ##### 重新啟動一個nginx鏡像 ``` docker run -p 443:443 -p 80:80 --name nginx \ --link jenkins \ -v /home/service/nginx/static:/usr/share/nginx/html \ -v /home/service/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /home/service/nginx/log:/var/log/nginx \ -v /home/service/nginx/conf.d:/etc/nginx/conf.d \ -v /home/service/nginx/ssl:/ssl \ -d nginx ``` ```-v```的意思就是把宿主機目錄掛載到冒號后面的容器目錄 ```--link```用于連接容器,后面是零一個容器的唯一name,這樣nginx就可以在配置文件使用```jenkins:端口```配置了 **此處多監聽了一個443端口,用于以后配置https** 修改一下nginx默認的```index.html```,更有辨識度 ```shell vim /home/service/nginx/static/index.html ``` #### 7.配置Https訪問 我是在阿里云申請了免費的一年ssl證書,大家可以百度一下,下載的是nginx的 并且在其中加入了許多優化的配置,```nginx.conf``` : ```shell user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include /etc/nginx/mime.types; default_type application/octet-stream; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; 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; server { listen 80; server_name www.example.com ; rewrite ^(.*)$ https://$host$1 permanent; } server { #監聽的端口號 listen 443 ssl; server_name www.example.com ; ssl_certificate /ssl/1492507_www.example.com.pem; ssl_certificate_key /ssl/1492507_www.example.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /usr/share/nginx/html; index index.html index.htm; } } include /etc/nginx/conf.d/*.conf; } ``` > 注意:這里更新的是宿主機上的nginx.conf > > 然后進入容器重啟nginx即可 >也可以不用進入容器重啟,直接重啟容器也可以 > ```docker restart nginx``` ```shell docker exec -it nginx /bin/bash nginx -s reload ``` 配置完成
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看