拉去nginx镜像

# docker pull nginx

运行nginx容器config用于拷贝nginx配置文件

# docker run --name nginxconfig -d docker.io/nginx

# docker cp nginxconfig:/etc/nginx/ /root/

删除

# docker stop nginxconfig

# docker rm nginxconfig

创建服务nginx容器

# docker run --name nginx -p 80:80 -p 443:443 -v /root/nginx/:/etc/nginx/ -d docker.io/nginx

  • 映射端口443,用于https请求
  • 映射端口80,用于http请求

nginx配置文件如下(不做任何修改)

[root@iZm5eclei4hhnwn6mo9va6Z ~]# ls
mysql  nginx   redis
[root@iZm5eclei4hhnwn6mo9va6Z ~]#
[root@iZm5eclei4hhnwn6mo9va6Z ~]# cd nginx
[root@iZm5eclei4hhnwn6mo9va6Z nginx]#
[root@iZm5eclei4hhnwn6mo9va6Z nginx]# ls
certs  conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params  uwsgi_params  win-utf
[root@iZm5eclei4hhnwn6mo9va6Z nginx]#
[root@iZm5eclei4hhnwn6mo9va6Z nginx]# cat nginx.conf
user  nginx;                                #运行nginx的用户
worker_processes  1;                        #启动进程设置成和CPU数量相等error_log  /var/log/nginx/error.log warn;   #全局错误日志
pid        /var/run/nginx.pid;              #PID文件的位置#工作模式及连接数上限
events {worker_connections  1024;               #单个后台work进程最大并发数设置为1024
}
http {include       /etc/nginx/mime.types;    #设定mime类型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;                             #开启GZIP压缩include /etc/nginx/conf.d/*.conf;
}
[root@iZm5eclei4hhnwn6mo9va6Z nginx]#

拷贝申请的阿里云ssl证书

[root@iZm5eclei4hhnwn6mo9va6Z nginx]# cd certs/
[root@iZm5eclei4hhnwn6mo9va6Z certs]#
[root@iZm5eclei4hhnwn6mo9va6Z certs]# ls
2032088_cnbi.jiaxin365.cn.key  2032088_cnbi.jiaxin365.cn.pem
[root@iZm5eclei4hhnwn6mo9va6Z certs]#
[root@iZm5eclei4hhnwn6mo9va6Z certs]# pwd
/root/nginx/certs

配置http自动跳往https

[root@iZm5eclei4hhnwn6mo9va6Z nginx]# cd conf.d/
[root@iZm5eclei4hhnwn6mo9va6Z conf.d]#
[root@iZm5eclei4hhnwn6mo9va6Z conf.d]# pwd
/root/nginx/conf.d
[root@iZm5eclei4hhnwn6mo9va6Z conf.d]#
[root@iZm5eclei4hhnwn6mo9va6Z conf.d]# ls
default.conf
[root@iZm5eclei4hhnwn6mo9va6Z conf.d]#
[root@iZm5eclei4hhnwn6mo9va6Z conf.d]# cat default.conf
server {server_name  cnbi.jiaxin365.cn;    #域名listen 80;                         #侦听80端口rewrite ^(.*) https://$server_name$1 permanent;       #${server_name}可以换成$host
    }                                                         #设置http自动跳转httpsserver {listen    443 ssl;                     #侦听443端口server_name  cnbi.jiaxin365.cn;        #域名#charset koi8-r;#access_log  /var/log/nginx/host.access.log  main;    # 增加sslssl on;                                #如果强制HTTPs访问,这行要打开ssl_certificate /etc/nginx/certs/2032088_cnbi.jiaxin365.cn.pem;ssl_certificate_key /etc/nginx/certs/2032088_cnbi.jiaxin365.cn.key;ssl_session_cache    shared:SSL:1m;ssl_session_timeout 5m;ssl_protocols  SSLv2 SSLv3 TLSv1.2;    # 指定密码为openssl支持的格式ssl_ciphers  HIGH:!aNULL:!MD5;         # 密码加密方式ssl_prefer_server_ciphers  on;         # 依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码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 {                #重定向错误页面到 /50x.htmlroot   /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;#}
}

重启容器

# docker restart nginx

查看容器是否启动成功

# docker ps -a

打开浏览器测试

参考博客:

nginx访问http80端口跳转https443端口

https://yq.aliyun.com/articles/556481

docker安装nginx并配置通过https访问

https://www.jianshu.com/p/5f9bd492f186

nginx配置ssl证书实现https访问

https://www.cnblogs.com/tianhei/p/7726505.html

nginx 80端口重定向到443端口

https://www.cnblogs.com/lxwphp/p/9820005.html

https://yq.aliyun.com/articles/601562

https://blog.csdn.net/weixin_31655741/article/details/82226688

转载于:https://www.cnblogs.com/djlsunshine/p/10671709.html

docker上部署nginx容器80端口自动转443端口相关推荐

  1. 在Docker上部署NGINX和NGINX Plus

    在Docker上部署NGINX和NGINX Plus 高性能应用程序交付平台NGINX Plus,负载均衡器和Web服务器可通过Docker容器部署. 先决条件 在Docker容器中运行NGINX开源 ...

  2. docker上启动nginx,并配置修改nginx的配置文件 nginx、挂载文件、docker容器中文乱码

    Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务.因为其优秀的性能,使得其成为日常开发,线上运营必不可少的软件了.下面就通过 ...

  3. Docker的配置与容器的拉取镜像、端口映射

    Docker的配置与容器的拉取镜像.端口映射 VM虚拟机的配置(linux redhat系统) 配置网络和软件源 docker docker容器介绍 虚拟机与容器技术对比 建立并配置容器 docker ...

  4. 采用docker安装部署Nginx

    四.采用docker安装部署Nginx 在主机192.168.1.138下,安装nginx,docker 的安装命令如下: docker run \ -d \ -p 8080:80 \ --name ...

  5. Docker中创建nginx容器出现docker: Error response from daemon: driver failed programming exter...解决

    使用nginx.conf配置文件创建nginx容器时出现: 解决: 根据出现的错误查找相应端口进程 netstat -apn | grep 80 找到后杀死进程 kill -9 954 重新启动Doc ...

  6. 阿里云/腾讯云服务器上部署Nginx,域名,SSL证书

    你将会从这篇文章中学到: 在服务器上部署Nginx. 域名的购买. 添加域名,让域名解析到你的服务器上. 教你如何添加SSL证书. 在你的服务器上面配置Nginx,实现http和https的访问. 如 ...

  7. nginx 80端口重定向到443端口

    nginx 80端口重定向到443端口,也就是http访问自动跳转到https 配置如下:  一.按照如下格式修改nginx.conf 配置文件,80端口会自动转给443端口,这样就强制使用SSL证书 ...

  8. Nginx如何跳转到非443端口的https

    前言 近一段时间由于看到*云服务厂商有活动,就注册并开了台云服务器,试一下区别. ("充10美元送30天内有效的250美元的免费额度,意思是30天内在 你加起来 不超出250美元的 服务随便 ...

  9. Linux上nginx配置SSL协议非80、443端口自动跳往https端口

    在生产环境中往往碰到一个网站需要多个访问端口,而默认的http访问端口是80,https访问的端口是443,然而这是不够在生产环境下使用的,这个时候就需要配置更多的端口来弥补这一缺点. 默认情况下用户 ...

最新文章

  1. Linux编程下open()函数的用法
  2. 区块链BaaS云服务(21)腾讯CCGP“跨链流程”
  3. 【必看】做了3年运维却不涨薪?那是你还没get这个技能
  4. 微型计算机kong控制技术,AT89C2051单片机在步进电机控制中的应用
  5. 一对一,一对多,多对多查询 (注解写法)
  6. 浅谈sql中的in与not in,exists与not exists的区别
  7. 计算机组成与设计第五版英文_教学设计gt;小学信息技术计算机的组成教师资格证面试模板...
  8. docker ubuntu安装python_BAT架构师手把手教你如何使用Docker安装GPU版本caffe2
  9. 《深入浅出struts》读书笔记(3)
  10. 强化学习在生成对抗网络文本生成中扮演的角色
  11. http中url的长度限制
  12. [FAQ03776] [Power]关于RTC唤醒系统问题
  13. Java 订单管理系统
  14. 计算机电缆对绞节距,耐高温双绞计算机电缆DJFFP2√厂家
  15. idea安装插件plugin(主要针对网络连接不上的情况)
  16. gba模拟器ios_不越狱iOS设备安装GBA模拟器 GBA4iOS 方法
  17. Python 解决warining的方法FutureWarning: warnings.warn(CV_WARNING, FutureWarning)
  18. 我们真的了解90后吗?
  19. php redis 分页查询,redis如何解决分页查询
  20. maven package后 Idea项目中找不到target文件

热门文章

  1. 云VR的未来发展方向
  2. linux看内存插槽,Linux查看内存大小和插槽
  3. 语音识别服务_语音识别服务厂商_腾讯云语音识别服务 - 云+社区 - 腾讯云
  4. CSDN自定义模块高级设置之(2)——设置主页左则及详情页背景(打造节日气氛)
  5. 中国IT研发实力最强的城市分析(转载)
  6. base cap 分布式_简单理解CAP-BASE
  7. 番茄工作法总结-第三章:方法
  8. 我心依旧之Android Camera模块FW/HAL3探学序
  9. 甜甜用计算机计算1050,NVIDIA GTX 1050/1050 Ti发布:75W功耗、取代GTX960
  10. 王者荣耀服务器ip地址配置文件,王者荣耀,关于设置的一些小技巧,知道以后你也是大神...