1.拉镜像

docker pull nginx:latest

2.创建目录

  /home/nginx/html

  /home/nginx/conf

  /home/nginx/logs

 

 

3.创建配置文件文件

  /home/nginx/conf/nginx.conf

worker_processes  1;

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

events {
    worker_connections  1024;
}

http {
    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;
    
    ssl on;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
 
    ssl_certificate /etc/nginx/cert/xxx.pem;             #证书路径
    ssl_certificate_key /etc/nginx/cert/xxx.key;         #请求认证 key 的路径

    server {
        listen    443;   #监听端口,ssl默认443端口。如果需要配置多个端口,可以继续添加server,用不同的端口就行
        server_name  www.xxx.com;   #服务器域名,需要和申请的证书匹配
        
        location / {
            root  /usr/share/nginx/html;  #网站根目录,和容器创建时指定的位置一致
            index index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
    }
}

 

4.将证书放至目录

/home/nginx/conf/cert

 

5.启动

docker run -d -p 80:80 -p 443:443 --name nginx-server -v /home/nginx/html:/usr/share/nginx/html -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx nginx

 

大功告成

 posted on 2021-11-02 21:59  絆τ  阅读(42)  评论(0编辑  收藏  举报