Docker配置Nginx篇------Docker学习(二)

目录

 

 

一、安装Nginx

二、配置Nginx

三、Nginx配置域名


 

一、安装Nginx

 

1.使用Docker下载Nginx镜像

docker pull nginx

2.查看已下载的Nginx镜像

docker images

3.启动Nginx容器

docker run --name docker-nginx -p 8080:80 -d nginx


--name:容器的名字

-p:端口映射,外部端口8080,内部端口80(将容器的80端口映射到主机的8080端口)

-d:设置容器在后台不断运行

4.查看效果


二、配置Nginx

1.在Linux创建要挂载的文件夹

    创建好的文件要与容器内的文件做一个挂载操作,这样修改服务器内的文件即可修改容器内的文件。我这里直接用Xftp做了文件创建。

2.将容器内Nginx的默认配置文件拷贝到挂载文件中

docker cp ffe3c800c168:/etc/nginx/nginx.conf /opt/myDocker/nginx/conf

 

3.运行部署命令

docker run -d -p 8080:80 --name docker-nginx -v /opt/myDocker/nginx/html:/usr/share/nginx/html -v /opt/myDocker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/myDocker/nginx/log:/var/log/nginx -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro  nginx

    此时修改/opt/myDocker/nginx/html下的index.html文件,页面内容即可更改。

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>


三、Nginx配置域名

1.修改nginx.conf文件


worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
		server_name www.mrfei.work;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
			root /usr/share/nginx/html;
			index index.html;
        }

        #error_page  404              /404.html;
    }
}

server_name:填写域名或localhost

2.使用docker重启Nginx

docker ps

docker restart 容器ID

docker ps 查看docker内容器

docker restart 容器id

 

要在 Docker 中部署配置 Nginx-RTMP,可以按照以下步骤进行操作: 1. 创建一个 Dockerfile 文件,以便构建自己的 Nginx 镜像。Dockerfile 内容如下: ``` FROM nginx:latest RUN apt-get update && apt-get install -y wget build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev RUN wget https://github.com/arut/nginx-rtmp-module/archive/master.zip && \ unzip master.zip RUN wget http://nginx.org/download/nginx-1.19.1.tar.gz && \ tar -zxvf nginx-1.19.1.tar.gz && \ cd nginx-1.19.1 && \ ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master && \ make && \ make install COPY nginx.conf /usr/local/nginx/conf/ ``` 2. 在 Dockerfile 目录中创建一个名为 nginx.conf 的 Nginx 配置文件,内容如下: ``` worker_processes 1; events { worker_connections 1024; } rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } application hls { live on; hls on; hls_path /tmp/hls; } } } http { server { listen 80; location /hls { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /tmp; add_header Cache-Control no-cache; } } } ``` 3. 构建 Docker 镜像,执行以下命令: ``` docker build -t nginx-rtmp . ``` 4. 运行 Docker 容器,执行以下命令: ``` docker run -d -p 1935:1935 -p 80:80 nginx-rtmp ``` 这将会在 Docker 容器中运行 Nginx,并将 RTMP 端口映射到主机的 1935 端口,将 HTTP 端口映射到主机的 80 端口。 现在,您可以使用 OBS 或其他 RTMP 客户端将视频流发送到 RTMP://<your-ip-address>:1935/live,并使用 VLC 播放器或其他支持 HLS 的浏览器,在 http://<your-ip-address>/hls 中查看视频。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值