docker は nginx コンテナーと構成ファイルのマウント ステートメント レコードを作成します

docker は nginx コンテナーと構成ファイルのマウント ステートメント レコードを作成します

nginxコマンドをプルする

docker  pull nginx

コンテナを作成して設定ファイルをマウントする通常のコマンド

  • html フォルダーはページの静的リソースにアクセスするためのもので、conf.d フォルダーは nginx 設定のサブファイル用で、nginx.conf ファイルの設定ファイル エントリ *
docker run --name nginx -p80:80 -v /etc/nginx/conf.d:/etc/nginx/conf.d -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/html:/usr/share/nginx/html -d nginx

コンテナを作成し、SSL証明書を構成するときに構成ファイルコマンドをマウントします。

  • 証明書用にもう 1 つのフォルダーをマウントします *
docker run --name nginx -p80:80 -p443:443 -v /etc/nginx/conf.d:/etc/nginx/conf.d -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/html:/usr/share/nginx/html -v /etc/nginx/cert:/etc/nginx/cert -d nginx

構成ファイルはSSL証明書を構成します

  • nginx 構成ファイルには、nginx.conf とdefault.conf の 2 つがあります。default.conf の内容は nginx.conf に導入されるため、default.conf の内容を変更するだけで済みます *
  server {
    listen       80; #http默认访问端口
    listen  443 ssl; #https默认访问端口
    server_name  域名;
	# 注意证书文件位置,是从/etc/nginx/下开始算起的
    ssl_certificate      cert/7796667_域名.pem;
    ssl_certificate_key  cert/7796667_域名.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers  on;
    #access_log  /var/log/nginx/host.access.log  main;

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

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
 }

おすすめ

転載: blog.csdn.net/weixin_42508580/article/details/124858179