最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Docker安裝Nginx并配置端口轉(zhuǎn)發(fā)問(wèn)題及解決方法

 更新時(shí)間:2022年01月23日 10:21:49   作者:daiyuenlong110  
這篇文章主要介紹了使用Docker安裝Nginx并配置端口轉(zhuǎn)發(fā),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

使用docker安裝并運(yùn)行nginx命令:

 docker run --name=nginx -p 80:80 -d docker.io/nginx

使用命令:

docker exec -it nginx /bin/bash 進(jìn)入容器可查看到幾個(gè)重要的文件

配置文件:nginx.conf 在 /etc/nginx/nginx.conf

日志文件: /var/log/nginx/access.log /var/log/nginx/error.log

使用cat命令打開(kāi)nginx.conf

root@dc048fc59765:/var/log/nginx# cat /etc/nginx/nginx.conf 
  user  nginx;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log warn;
  pid        /var/run/nginx.pid;
  
  
 events {
     worker_connections  1024;
     }
 
 http {
     include       /etc/nginx/mime.types;
     default_type  application/octet-stream;
 
     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;
 
     keepalive_timeout  65;
 
     #gzip  on;
 
     include /etc/nginx/conf.d/*.conf;
 }
 root@dc048fc59765:/var/log/nginx#

發(fā)現(xiàn)第32行,配置了一個(gè)子配置文件,進(jìn)入conf.d發(fā)現(xiàn)有一個(gè)default.conf文件

打開(kāi)default.conf文件:

root@dc048fc59765:/etc/nginx/conf.d# cat default.conf 
  server {
      listen       80;
      listen  [::]:80;
      server_name  localhost;
  
      #charset koi8-r;
      #access_log  /var/log/nginx/host.access.log  main;
     location / {
         root   /usr/share/nginx/html;
         index  index.html index.htm;
     }
 
     #error_page  404              /404.html;
     # redirect server error pages to the static page /50x.html
     #
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
     # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     #location ~ \.php$ {
     #    proxy_pass   http://127.0.0.1;
     #}
     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #    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;
 }
 root@dc048fc59765:/etc/nginx/conf.d# 

在瀏覽器中輸入:http://192.168.11.241

 從default.conf中11行可以看出,index頁(yè)面在/usr/share/nginx/html

現(xiàn)在,我們配置一下容器卷:

docker rm -f nginx 刪除一下之前的容器

再次執(zhí)行比較完整的命令:

 docker run \
  --restart=always \
  --name nginx \
  -d -p 80:80 \
  -v /data/nginx/html:/usr/share/nginx/html \
  -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf \
  -v /data/nginx/conf.d:/etc/nginx/conf.d \
  -v /data/nginx/log:/var/log/nginx \
  nginx

這里有幾個(gè)注意事項(xiàng):

(1)第一個(gè)“-v”,是項(xiàng)目位置,把html代碼放到掛載到的目錄下即可;

(2)第二個(gè)“-v”,是掛載的主配置文件"nginx.conf",注意"nginx.conf"文件內(nèi)有一行"include /etc/nginx/conf.d/*.conf;",

         這個(gè)include指向了子配置文件的路徑,此處注意include后所跟的路徑一定不要出錯(cuò)。

(3)第三個(gè)“-v”,把docker內(nèi)子配置文件的路徑也掛載了出來(lái),注意要與(2)中include指向路徑一致

(4)重點(diǎn)強(qiáng)調(diào)一下,nginx.conf是掛載了一個(gè)文件(docker是不推薦這樣用的),conf.d掛載的是一個(gè)目錄

我們先啟動(dòng)一下,可以發(fā)現(xiàn)是有問(wèn)題的,因?yàn)榕渲梦募€沒(méi)有。

[root@zuul-server data]# docker run  --name nginx  -d -p 80:80  -v /data/nginx/html:/usr/share/nginx/html  -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/conf.d:/etc/nginx/conf.d  -v /data/nginx/log:/var/log/nginx  nginx

c8d49810b4afd4b6661beb942f0f19a67cf64f9798af9d2eb8a2aa242b2af434

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/data/nginx/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/ee154ee69264707a542409b514cfff950b31cefa4dcd4e66c3635d0aa94f5058/merged\\\" at \\\"/var/lib/docker/overlay2/ee154ee69264707a542409b514cfff950b31cefa4dcd4e66c3635d0aa94f5058/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

很明顯,報(bào)錯(cuò)了,容器也沒(méi)有啟動(dòng)成功,怎么解決了?

解決辦法:

1 進(jìn)入/data/nginx目錄,

2 刪除nginx.conf文件夾  rm  -rf nginx.conf

3 新建nginx.conf文件    touch nginx.conf

4 然后把之前cat /etc/nginx/nginx.conf的內(nèi)容放入到nginx.conf

5 同理,cd /data/nginx/conf.d ,touch default.conf,把之前 cat /etc/nginx/conf.d/default.conf中的內(nèi)容放入到新建的default.conf中。

最后 docker restart nginx 搞定。

 需要配置一個(gè)端口轉(zhuǎn)發(fā)功能,業(yè)務(wù)需求是:以http://192.168.11/241/mp開(kāi)頭的請(qǐng)求需要重定向到http://192.168.11.241:20001/mp上,

剛開(kāi)始把 proxy_pass 對(duì)應(yīng)的路徑寫(xiě)成了 http://127.0.0.1:20001/;導(dǎo)致報(bào)404錯(cuò)誤,原因很簡(jiǎn)單,nginx運(yùn)作在容器里面,肯定找不到http://127.0.0.1:20001/,浪費(fèi)了我一點(diǎn)點(diǎn)時(shí)間,一時(shí)沒(méi)轉(zhuǎn)過(guò)彎來(lái)。

 server {
   listen  80;
   server_name localhost;
    
   #charset koi8-r;
   #access_log /var/log/nginx/log/host.access.log main;
    
   location / {
    #root /usr/nginx/dacheng-wechat-web;
   #root /usr/nginx/html;
   root /usr/share/nginx/html;
   index index.html index.htm;
   autoindex on;
   # try_files $uri /index/index/page.html;
   # try_files $uri /index/map/page.html;
  }
 
 location /mp {
   proxy_pass http://192.168.11.241:20001/;
 
 }   
  #error_page 404    /404.html;
   
  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
   root /usr/share/nginx/html;
  }
   
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  # proxy_pass http://127.0.0.1;
  #}
   
  # 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;
  #}
 }

到此這篇關(guān)于使用Docker安裝Nginx并配置端口轉(zhuǎn)發(fā)的文章就介紹到這了,更多相關(guān)Docker安裝Nginx配置端口轉(zhuǎn)發(fā)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • docker-compose啟動(dòng)服務(wù)方式

    docker-compose啟動(dòng)服務(wù)方式

    這篇文章主要介紹了docker-compose啟動(dòng)服務(wù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • docker容器增加端口映射全過(guò)程(修改配置文件方式)

    docker容器增加端口映射全過(guò)程(修改配置文件方式)

    文章詳細(xì)描述了如何通過(guò)修改Docker容器的配置文件來(lái)增加端口映射,以解決已經(jīng)運(yùn)行的容器需要增加端口映射的問(wèn)題,以MySQL容器為例進(jìn)行了具體操作步驟的說(shuō)明
    2024-11-11
  • 詳解docker pull 下來(lái)的鏡像文件存放的位置

    詳解docker pull 下來(lái)的鏡像文件存放的位置

    本篇文章主要介紹了詳解docker pull 下來(lái)的鏡像文件存放的位置,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-04-04
  • Centos 7中Docker私有倉(cāng)庫(kù)的搭建方法

    Centos 7中Docker私有倉(cāng)庫(kù)的搭建方法

    本篇文章主要介紹了Centos 7中Docker私有倉(cāng)庫(kù)的搭建方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-04-04
  • 刪除docker容器中內(nèi)容后打包鏡像不變小問(wèn)題及解決

    刪除docker容器中內(nèi)容后打包鏡像不變小問(wèn)題及解決

    文章討論了在Docker中處理大壓縮包時(shí)遇到的問(wèn)題,以及如何通過(guò)分層存儲(chǔ)和使用`docker load`與`docker import`命令來(lái)解決鏡像大小過(guò)大的問(wèn)題
    2025-03-03
  • Docker鏡像優(yōu)化打包速度思考

    Docker鏡像優(yōu)化打包速度思考

    本文主要介紹了Docker鏡像優(yōu)化打包速度思考,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • 使用docker安裝部署NextCloud私人網(wǎng)盤(pán)的方法步驟

    使用docker安裝部署NextCloud私人網(wǎng)盤(pán)的方法步驟

    本文主要介紹了使用docker安裝部署NextCloud私人網(wǎng)盤(pán)的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • centOS7安裝docker的詳細(xì)步驟

    centOS7安裝docker的詳細(xì)步驟

    這篇文章主要為大家介紹了centOS7安裝docker的詳細(xì)步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 關(guān)于docker啟動(dòng)jenkins環(huán)境的問(wèn)題

    關(guān)于docker啟動(dòng)jenkins環(huán)境的問(wèn)題

    這篇文章主要介紹了docker啟動(dòng)jenkins環(huán)境的問(wèn)題,文中提到了jenkins基本工作原理及管理員密碼獲取方法,對(duì)docker啟動(dòng)jenkins環(huán)境相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-04-04
  • docker環(huán)境中websocket?通過(guò)nginx代理不通解決方案

    docker環(huán)境中websocket?通過(guò)nginx代理不通解決方案

    這篇文章主要介紹了docker環(huán)境中websocket?通過(guò)nginx代理不通解決方案,下面是一些可能會(huì)導(dǎo)致?WebSocket?代理失敗的問(wèn)題以及相應(yīng)的解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05

最新評(píng)論

芮城县| 溧水县| 永平县| 秦安县| 乌兰浩特市| 临江市| 宜宾市| 达孜县| 阳朔县| 江达县| 谷城县| 榆树市| 和静县| 广河县| 通州区| 米易县| 东至县| 基隆市| 温泉县| 蓝山县| 丰镇市| 北海市| 灵石县| 竹山县| 汉沽区| 太康县| 平遥县| 苍山县| 公主岭市| 峨眉山市| 和龙市| 大方县| 墨江| 惠水县| 扬中市| 来宾市| 阜平县| 济宁市| 五寨县| 泰兴市| 永定县|