docker 创建nginx容器以及配置文件挂载语句记录

4 篇文章 0 订阅
2 篇文章 0 订阅

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证书时创建容器并挂载配置文件命令

  • 多挂载一个放证书的文件夹 *
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。nginx.conf里面引入了default.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;
    #}
 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值