docker nginx ssl

1.目錄/文件準(zhǔn)備

生成一個(gè)容器并拷貝出相應(yīng)的文件和目錄

docker run --name nginx -p 80:80 -d nginx
docker cp nginx:/etc/nginx/nginx.conf /home/site/conf/
docker cp nginx:/etc/nginx/conf.d /home/site/

2.上傳相應(yīng)ssl文件到目錄下

scp xxxx.pem user@100.111.222.333:/home/site/ssl
scp xxxx.key user@100.111.222.333:/home/site/ssl

3. nginx.conf 配置文件

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server {
    listen 443 ssl;
    server_name www.guobao.art;
    ssl_certificate /etc/nginx/ssl/xxxx.pem; 
    ssl_certificate_key /etc/nginx/ssl/xxxx.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADM:!RC4;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        }
    }

    server {
    listen 80;
    server_name www.guobao.art;
    rewrite ^(.*)$ https://$server_name$1 permanent;
    location / {
        index index.html index.htm;
        }
    }
    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;

    include /etc/nginx/conf.d/*.conf;
}

4.docker生成容器

docker run -it -p 80:80 -p 443:443 -v /home/site/webfile:/usr/share/nginx/html -v /home/site/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/site/cert:/etc/nginx/ssl -v /home/site/conf.d:/etc/nginx/conf.d -v /home/site/log:/var/log/nginx --privileged=true -d --restart=always nginx
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容