• docker nginx 自定义配置容器


    准备

    • 拉取nginx官方镜像

    docker pull nginx
    
    • etc/nginx/ 下新建目录 cert 和 conf

    cert 存放证书
    conf 存放配置文件

    mkdir /etc/nginx/cert
    mkdir /etc/nginx/conf
    
    • /etc/nginx/下新建nginx.conf 配置文件

    
    user  root;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/log/nginx/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;
    
        client_max_body_size 100m;
    
        include /etc/nginx/conf.d/*.conf;
    }
    
    #TCP转发配置目录
    include /etc/nginx/tcp.d/*.conf;
    
    

    启动容器

    docker run --restart=always -d --name nginx1 -v /etc/nginx/cert:/etc/nginx/cert -v /etc/nginx/conf.d:/etc/nginx/conf.d  -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx -v /home/nginx/cache:/home/nginx/cache -p 80:80 -p 443:443 nginx
    

    测试

    访问IP看看是否正常,若有异常可用 docker log 容器id 进行查看错误日志后处理

    扩展

    教程到这里已经到了这里,基本的nginx代理已经可以了,小伙伴可以自己尝试着配置转发到其他服务,如nps.配置双代理,冗余保证.

    但是域名访问还是http,有些接口开发中需要https,这个就没辙了,所以下一篇教程就是申请https泛域名解析

  • 相关阅读:
    Centos7开启telnet登录
    Centos7编译openssh8.9p1
    20220613复盘
    20220614复盘
    20220610复盘
    Maven打包遇到No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    如何隐藏滚动条,但是保留滚动效果?(考虑兼容性)
    Oracle高效查询数据是否已经存在
    Django框架redder函数的功能
    VUE框架 ajax请求案例天气预报
  • 原文地址:https://www.cnblogs.com/LandWind/p/docker-customer-nginx.html
Copyright © 2020-2023  润新知