nginx的location配置-docker映射的nginx

这是我的映射配置

docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx \
-v /mydata/nginx/conf:/etc/nginx \
-d nginx:1.10

很明显我映射出来的nginx地址是:/mydata/nginx/html

docker里面nginx地址是:/usr/share/nginx/html

这是我最初的nginx配置

    location / {
        root /usr/share/nginx/html;
        index  index.html index.htm;
    }
    location /wx {
        alias /mydata/nginx/html/wx/static/html;
        index  main.html;
    }
    location /zj {
        alias /mydata/nginx/html/wx/static/;
        index  zhuanji.html;
    }

配置后,/wx,/zj怎么修改路径都不生效,root alias都试了好几遍,最后去看了nginx日志,

日志路径:

映射的日志地址: /mydata/nginx/logs   

docker里面nginx的日志地址:/var/log/nginx

看的是error日志,

2022/08/27 06:33:37 [error] 7#7: *1 open() "/mydata/nginx/html/wx/static/zhuanji.html" failed (2: No such file or directory)

报错也比较明显,没有找到这个文件和路径,但是我找了下,是有这个文件和路径的,后天突然想到docker里面的nginx是没有这个路径的,所以路径按照docker里面的路径地址改了下,配置如下

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

    location /wx {
        alias /usr/share/nginx/html/wx/static/html;
        index  main.html;
    }
    location /zj {
        alias /usr/share/nginx/html/wx/static/;
        index  zhuanji.html;
    }

之后就成功了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在 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
发出的红包

打赏作者

不积跬步无以至千里-陕西西安

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值