• 【Vegas原创】Docker安装Nginx,并配置端口转发,配置SSL


    1,docker安装Nginx

    [root@hecs-29489 ~]# docker pull nginx
    Using default tag: latest
    latest: Pulling from library/nginx
    b4d181a07f80: Already exists 
    66b1c490df3f: Pull complete 
    d0f91ae9b44c: Pull complete 
    baf987068537: Pull complete 
    6bbc76cbebeb: Pull complete 
    32b766478bc2: Pull complete 
    Digest: sha256:353c20f74d9b6aee359f30e8e4f69c3d7eaea2f610681c4a95849a2fd7c497f9
    Status: Downloaded newer image for nginx:latest
    docker.io/library/nginx:latest


    2,docker run Nginx,默认80 ,443

    [root@hecs-29489 ~]# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
    nginx        latest    4cdc5dd7eaad   12 days ago   133MB
    wordpress    latest    b77ea6f8ecf7   2 weeks ago   551MB
    mysql        latest    5c62e459e087   3 weeks ago   556MB
    [root@hecs-29489 ~]# docker run --name nginx -p 80:80 -p 443:443 -d nginx
    35a903217fb79e8bf0d8c7855b57d2d7be5fa873a887acd44c34b415d69cfb7c


    3,进容器,改配置文件: cp 一个default.conf 到 default.con 备份,然后 vi

    [root@hecs-29489 ~]# docker exec -it nginx bash
    root@35a903217fb7:/# apt-get update
    Hit:1 http://security.debian.org/debian-security buster/updates InRelease
    Hit:2 http://deb.debian.org/debian buster InRelease                      
    Hit:3 http://deb.debian.org/debian buster-updates InRelease
    Reading package lists... Done
    root@35a903217fb7:/# apt-get install vim
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      libgpm2 vim-common vim-runtime xxd
    Processing triggers for libc-bin (2.28-10) ...
    


    root@35a903217fb7:/etc/nginx/conf.d# vi /etc/nginx/conf.d/default.conf


    4,配置Nginx :

    server{
        listen 80;
        server_name jesus.weyomusic.com;
        location / {
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass  http://192.168.0.199:81;
        }
    }
    server{
        listen 80;
        listen 443 ssl;
        server_name weyomusic.com www.weyomusic.com;
            ssl_certificate      cert/server.crt;
            ssl_certificate_key  cert/server.key;
            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;
            ssl_ciphers  HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers  on;
    
    location / {
            proxy_set_header HOST $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://124.71.155.60:81;
            client_max_body_size 1024M;
        }
    }


    5,docker中VI,显示 vi visual:

    在命令中 输入::set mouse-=a


    6,在docker的nginx目录下 (/etc/nginx)执行test,确保nginx的配置正确·

    root@9e7828a6f89e:/etc/nginx# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful


    7,exit到本地,docker restart nginx

    喜欢请赞赏一下啦^_^
  • 相关阅读:
    dfs模板
    24点
    个人阅读三
    个人阅读作业2:关于项目经历的心得
    代码复审
    Pair Project1:电梯控制程序
    第二次个人项目——阅读经典教材
    THE First Individual Project
    个人阅读作业3
    个人阅读作业2
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/15029552.html
Copyright © 2020-2023  润新知