亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

使用docker安裝并運行nginx命令:

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

使用命令:

docker exec -it nginx /bin/bash 進入容器可查看到幾個重要的文件

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

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

使用cat命令打開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行,配置了一個子配置文件,進入conf.d發(fā)現(xiàn)有一個default.conf文件

打開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頁面在/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

這里有幾個注意事項:

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

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

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

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

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

我們先啟動一下,可以發(fā)現(xiàn)是有問題的,因為配置文件還沒有。

[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.

很明顯,報錯了,容器也沒有啟動成功,怎么解決了?

解決辦法:

1 進入/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 搞定。

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

剛開始把 proxy_pass 對應的路徑寫成了 http://127.0.0.1:20001/;導致報404錯誤,原因很簡單,nginx運作在容器里面,肯定找不到http://127.0.0.1:20001/,浪費了我一點點時間,一時沒轉(zhuǎn)過彎來。

 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • docker版es、milvus、minio啟動命令詳解

    docker版es、milvus、minio啟動命令詳解

    這篇文章主要介紹了docker版es、milvus、minio啟動命令詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • docker部署minio并使用springboot連接的操作方法

    docker部署minio并使用springboot連接的操作方法

    這篇文章主要介紹了docker部署minio并使用springboot連接的操作方法,本文以minio為例結(jié)合實例代碼給大家詳細講解,需要的朋友可以參考下
    2023-11-11
  • 使用Docker搭建Apache Kafka環(huán)境的詳細過程

    使用Docker搭建Apache Kafka環(huán)境的詳細過程

    這篇文章主要介紹了使用Docker搭建Apache Kafka環(huán)境,本文使用Docker技術(shù)創(chuàng)建單個Kafka節(jié)點和Kafka集群環(huán)境,并且使用可視化工具連接服務(wù)查看代理服務(wù)器的配置信息,需要的朋友可以參考下
    2022-10-10
  • Docker如何部署前端項目

    Docker如何部署前端項目

    這篇文章主要介紹了Docker如何部署前端項目問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Vulhub漏洞靶場搭建圖文教程

    Vulhub漏洞靶場搭建圖文教程

    這篇文章主要介紹了Vulhub漏洞靶場搭建圖文教程,本文圖文講解全流程安裝搭建過程,簡單易懂,需要的朋友可以參考下
    2023-03-03
  • 開啟Docker的TCP通信端口方式

    開啟Docker的TCP通信端口方式

    這篇文章主要介紹了開啟Docker的TCP通信端口方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Linux上使用docker啟動redis并遠程訪問的實現(xiàn)

    Linux上使用docker啟動redis并遠程訪問的實現(xiàn)

    這篇文章主要介紹了Linux上使用docker啟動redis并遠程訪問的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • docker?環(huán)境搭建、docker?與容器常用指令大全(推薦)

    docker?環(huán)境搭建、docker?與容器常用指令大全(推薦)

    這篇文章主要介紹了docker?環(huán)境搭建、docker?與容器常用指令大全,主要包括docker容器操作命令匯總,文中介紹需要注意的是如果想要刪除一個容器,需要先停止該容器且如果鏡像中有運行狀態(tài)的容器,也是無法刪除容器的,需要的朋友可以參考下
    2022-06-06
  • 安裝harbor作為docker鏡像倉庫的問題

    安裝harbor作為docker鏡像倉庫的問題

    這篇文章主要介紹了安裝harbor作為docker鏡像倉庫,主要包括docker和docker-compose離線部署,安裝harbor作為本地的倉庫,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • 編寫最佳的Dockerfile的方法

    編寫最佳的Dockerfile的方法

    本文給大家分享的是如何編寫最佳的dockerfile的方法,通過具體實例幫助大家快速掌握編寫Dockerfile的技巧
    2017-06-06

最新評論