docker上部署nginx容器80端口自动转443端口
拉去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 ; #启动进程设置成和CPU数量相等 error_log /var/log/nginx/error.log warn; #全局错误日志
pid /var/run/nginx.pid; #PID文件的位置 #工作模式及连接数上限
events {
worker_connections ; #单个后台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 ; #设置连接超时的事件 #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端口
rewrite ^(.*) https://$server_name$1 permanent; #${server_name}可以换成$host
} #设置http自动跳转https server {
listen ssl; #侦听443端口
server_name cnbi.jiaxin365.cn; #域名 #charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
# 增加ssl
ssl 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.; # 指定密码为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 /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html { #重定向错误页面到 /50x.html
root /usr/share/nginx/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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
docker上部署nginx容器80端口自动转443端口的更多相关文章
- docker - compose 部署 Nginx
主要介绍 docker 中 Nginx 的部署及项目目录挂载券的方法.docker 中部署一个服务,有三种方法,分别是 docker run.Dockerfile.docker-compose . 下 ...
- 在Docker下部署Nginx
在Docker下部署Nginx 在Docker下部署Nginx,包括: 部署一个最简单的Nginx,可以通过80端口访问默认的网站 设置记录访问和错误日志的路径 设置静态网站的路径 通过proxy_p ...
- docker上启动nginx,并配置修改nginx的配置文件
1.使用docker 下载nginx 镜像 docker pull nginx 2.启动nginx docker run --name nginx -p 80:80 -d nginx 这样就简单的把 ...
- 阿里云服务器安装Docker并部署nginx、jdk、redis、mysql
阿里云服务器安装Docker并部署nginx.jdk.redis.mysql 一.安装Docker 1.安装Docker的依赖库 yum install -y yum-utils device-map ...
- 定期从Docker上部署的MySQL备份数据
前段时间公司停电,正巧赶上周一领导要开会要过一遍项目,然而项目所依赖的MySQL数据库是直接部署在宿主机,且因为各人部署方式不同的原因,花了很久才在开会前启动起来.于是开完会后,我第一件事就是把原先依 ...
- Docker Compose部署 nginx代理Tomcat集群
一.简介 使用Docker镜像部署Nginx代理的多个Tomcat集群: 使用Dockerfile构建nginx镜像 使用Dockerfile构建tomcat镜像 mysql镜像使用docker hu ...
- docker上构建redis容器
1.查看docker上的镜像 [root@holly ~]# docker images 2.搜索docker上的redis镜像,选择下载的版本 [root@holly ~]# docker sear ...
- 在Docker上部署自动更新ssl证书的nginx + .NET CORE
突发奇想要搞一个ssl的服务器,然后我就打起了docker的主意,想着能不能搞一个基于Docker的服务器,这样维护起来也方便一点. 设想 想法是满足这么几点: .NET CORE on Docker ...
- docker一键搭建Nginx+PHP环境(含自动部署命令)
文章的主要部分是一步一步的教程,文章的最后是我整理好的一键安装命令,自动下载并安装docker,构建镜像,启动容器集群(压缩包内注释覆盖范围达到80%) 大家可以看完教程亲自尝试下,也可以直接执行一键 ...
随机推荐
- Loadrunner加密算法脚本与token作为get请求url上的参数处理
1.当字符串被封装好加密时(下例将算法封装在md5中),使用Loadrunner编写脚本,需要进行如下操作: 1)将md5.h文件添加到Extra Files 下,如图(Loadrunne ...
- unity中 UGUI的按下、拖动接口事件的实现
using UnityEngine; using System.Collections.Generic; using DG.Tweening; using UnityEngine.EventSyste ...
- Andriod Studio两种签名机制V1和V2的区别
Android Studio 2.2以上版本打包apk的时候,我们会发现多了个签名版本(v1.v2)选择,如下图红色方框所示 问题描述(v1和v2) Android 7.0中引入了APK Signat ...
- Linux SSH登录很慢的解决方法
一:UseDNS OpenSSH在用户登录的时候会验证IP,它根据用户的IP使用反向DNS找到主机名,再使用DNS找到IP地址,最后匹配一下登录的IP是否合法.如果客户机的IP没有域名,或者DNS服务 ...
- centos安装ruby
下面开始安装Ruby 一.下载Ruby源码包 wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.7.tar.gz 二.解压安装Ruby tar zx ...
- c、c++函数随机
#inlcude<algorithm> next_permutation函数<全排列函数> #include<stdio.h> #include<algori ...
- JavaScript的组成 | DOM/BOM
往期回顾 在上一期的<JavaScript的组成 | 核心-ECMAScript >☜里,我们有说到JavaScript 是由三大部分组成,分别是:核心ECMAScript.文档对象模型- ...
- IIC_slaver 的仿真之路
IIC_slaver 是网上下载的.testbench文件是自带的,出现如图错误. compile >> compile option >> include direct ...
- MacOs 安装cordova报无权访问题解决方案
在MacOS安装cordova后,执行cordova -v报错: Error: EACCES: permission denied, open '/Users/jianuonuo/.config/co ...
- 10--Python入门--异常处理
在程序编写过程中,难免会有一些错误.python中有一些语句可以处理这些异常或者错误,使得程序能够运行,且识别到错误的位置 try..except函数,java中是try catch 在下面的例子中, ...