溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

docker nginx服務(wù)如何部署

發(fā)布時(shí)間:2021-11-30 11:53:38 來源:億速云 閱讀:146 作者:iii 欄目:云計(jì)算

這篇文章主要講解了“docker nginx服務(wù)如何部署”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“docker nginx服務(wù)如何部署”吧!

1.下載nginx
docker pull nginx 

2.啟動(dòng)nginx

docker run -d -m 2g -p 8888:80 --name lyjng nginx

3.配置映射

創(chuàng)建目錄:  mkdir -p  /root/lyjnginx/nginx/www /root/lyjnginx/nginx/logs /root/lyjnginx/nginx/conf

其中:

      www: 目錄將映射為 nginx 容器配置的虛擬目錄。
      logs: 目錄將映射為 nginx 容器的日志目錄。
      conf: 目錄里的配置文件將映射為 nginx 容器的配置文件。

4.復(fù)制docker容器中的文件

[root@ambari-01 lyjnginx]# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                  NAMES
cf7da4042664   nginx     "/docker-entrypoint.…"   20 minutes ago   Up 20 minutes   0.0.0.0:8888->80/tcp   lyjng
[root@ambari-01 lyjnginx]# docker cp cf7da4042664:/etc/nginx/nginx.conf /root/lyjnginx/nginx/conf/

5.部署命令

docker run -m 2g --rm -d -p 8889:80 --name nginx-test-web   -v /root/lyjnginx/nginx/www:/usr/share/nginx/html   -v /root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf   -v /root/lyjnginx/nginx/logs:/var/log/nginx   nginx

命令說明:

       -m : 設(shè)置容器占用內(nèi)存
      --rm:容器終止運(yùn)行后,自動(dòng)刪除容器文件。
      -p 8889:80: 將容器的 80 端口映射到主機(jī)的8889端口.
      --name nginx-test-web:將容器命名為 nginx-test-web 
      -v /root/lyjnginx/nginx/www:/usr/share/nginx/html:將我們自己創(chuàng)建的 www 目錄掛載到容器的 /usr/share/nginx/html。
      -v /root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:將我們自己創(chuàng)建的 nginx.conf 掛載到容器的 /etc/nginx/nginx.conf。
      -v /root/lyjnginx/nginx/logs:/var/log/nginx:將我們自己創(chuàng)建的 logs 掛載到容器的 /var/log/nginx。

6.添加網(wǎng)頁 將vue打包的文件復(fù)制到/root/lyjnginx/nginx/www/ 這個(gè)目錄下就能訪問了

[root@ambari-01 conf]# cd /root/lyjnginx/nginx/www/
[root@ambari-01 www]# vim index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Nginx test !!!</title>
</head>
<body>
    <h2>我的第一個(gè)標(biāo)題</h2>
    <p>我的第一個(gè)段落。</p>
</body>
</html>

7.問題nginx代理轉(zhuǎn)發(fā)一致報(bào)404不生效問題

vim  /root/lyjnginx/nginx/conf/nginx.conf 這個(gè)配置文件注釋掉# include /etc/nginx/conf.d/*.conf;

# 這行必須注釋否則/etc/nginx/conf.d/*.conf 會(huì)覆蓋下面server{}中的配置
   # include /etc/nginx/conf.d/*.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;
   # 這行必須注釋否則/etc/nginx/conf.d/*.conf 會(huì)覆蓋下面server{}中的配置
   # include /etc/nginx/conf.d/*.conf;
    #lyj add
     server {
          listen       80;
          server_name  localhost;
  
          location / {
             # root   /root/lyjnginx/bigdata_product;
	      root    /usr/share/nginx/html;
              index  index.html index.htm;
          }
          location /prod-api/ {
               proxy_pass http://192.168.3.175:8002/;
          }
          location /prod-api-extract/ {
                 proxy_pass http://192.168.1.134:8003/;
          }
           location /prod-api-dataxJ/ {
                proxy_pass http://192.168.3.173:8008/;
          }
           location /prod-api-datax/ {
                 proxy_pass http://192.168.1.134:9527/;
          }
       }
    #lyj add

}

感謝各位的閱讀,以上就是“docker nginx服務(wù)如何部署”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)docker nginx服務(wù)如何部署這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI