docker-compose搭建带证书nginx静态资源服务器

docker-compose.yml

version: '3.1'
services:
  nginx:
    restart: always
    image: nginx
    container_name: nginx
    ports:
     #暴露80和443端口
      - 80:80
      - 443:443
    volumes:
      - ./conf/1_domain.cn_bundle.crt:/etc/nginx/1_domain.cn_bundle.crt
      - ./conf/2_domain.cn.key:/etc/nginx/2_domain.cn.key
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./wwwroot:/usr/share/nginx/wwwroot
      - ./videos:/usr/share/nginx/videos

nginx.conf

worker_processes  1;

events {
    use epoll;
    worker_connections  1024;
}

http {
        server {
        listen 443 ssl;
        server_name www.domain.cn;
        root /usr/share/nginx/wwwroot;
        index index.html index.htm;
        ssl_certificate  1_domain.cn_bundle.crt;
        ssl_certificate_key 2_domain.cn.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        location /videos/ {
           #文件夹路径
            root  /usr/share/nginx/;
            autoindex on;
      }

        }
        #http自动转https
        server {
        listen 80;
        server_name www.domain.cn;
        rewrite ^(.*)$ https://$host$1 permanent;
        }
}

范文路径:www.domain.cn/videos/

你可能感兴趣的:(docker-compose搭建带证书nginx静态资源服务器)