美文网首页
Docker 安装Nginx

Docker 安装Nginx

作者: 一二先生 | 来源:发表于2020-02-14 15:50 被阅读0次
  • 搜索相关Nginx镜像

    docker search nginx
    
  • 下载选定的Jenkins镜像,这里我们选择官方镜像,如果未指定版本则默认为最新版本,latest版本

    docker pull nginx
    
  • 运行镜像

    docker run -d -p 80:80 --name nginx nginx
    
  • 映射容器工作目录

    docker cp {container}:/etc/nginx /home/nginx/conf
    docker cp {container}:/usr/share/nginx/html /home/nginx/html
    
  • 删除容器

      docker rm -f {container}
    
  • 重新运行镜像

    docker run -d -p 80:80 -v /home/nginx/conf:/etc/nginx -v /home/nginx/html:/usr/share/nginx/html --name nginx nginx
    
  • 配置

    # 修改/home/nginx/conf/conf.d/default.conf文件并重启容器,nginx配置就能更改生效
    # 阿里云可申请免费SSL证书
    # 阿里云nginx https配置帮助(cert目录创建在conf.d的同级):https://help.aliyun.com/document_detail/98728.html?spm=5176.2020520154.0.0.8d1cJjXIJjXI8U
     
    server {
     listen       80;
     server_name  www.eairlv.com;
       
     # rewrite ^(.*)$ https://$host$1 permanent;   #将所有http请求通过rewrite重定向到https
       
     #charset koi8-r;
     #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;
     #}
    }
    server {
     listen  443 ssl;   #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
     server_name www.eairlv.com;  #将localhost修改为您证书绑定的域名,例如:www.example.com。
     ssl_certificate cert/3352148.pem;   #将domain name.pem替换成您证书的文件名。
     ssl_certificate_key cert/3352148.key;   #将domain name.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 / {
         root   /usr/share/nginx/html;
         index  index.html index.htm;
     }
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
         root   /usr/share/nginx/html;
     }
    }    
    

相关文章

网友评论

      本文标题:Docker 安装Nginx

      本文链接:https://www.haomeiwen.com/subject/tdwspctx.html