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%) 大家可以看完教程亲自尝试下,也可以直接执行一键 ...
随机推荐
- 若依项目分模块集成uflo2
关于若依分模块创建项目可参考:https://www.cnblogs.com/conswin/p/9766186.html 了解uflo2,uflo2是一套由BSTEK自主研发的基于Java的工作流引 ...
- 3. Longest Substring Without Repeating Characters无重复字符的最长子串
网址:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 显然采用sliding window滑 ...
- 在 .NET项目中使用 Redis(2018.10.16)
1. 打开NuGet管理器搜索redis,安装:“StackExchange.Redis” 2. 配置 Web.config 文件 <connectionStrings> <add ...
- [Codeforces477D]Dreamoon and Binary
Problem 给定一个字符串数的二进制表示(不含前导0)s(长度不超过5000), 对于一个数n(初值为0),可以进行以下两种操作: 1.将n的二进制表示(无前导0)写到已经写的串的后面. 2.n加 ...
- 二十四. Python基础(24)--封装
二十四. Python基础(24)--封装 ● 知识结构 ● 类属性和__slots__属性 class Student(object): grade = 3 # 也可以写在__slots ...
- 禁止WORDPRESS站内搜索的方法
如果我们希望禁止站内搜索,毕竟会是的MYSQL负担加重,我们可以禁止掉,然后在使用第三方搜索组件.比如用百度站内搜索或者360站内搜索. function fb_filter_query( $quer ...
- Python基础03_pycharm
pycharm的安装还是很简单的,一路next. 看起来Jet Brains 家的产品长相都差不多啊. 主要是create new project时,路径和解释器的选择,我电脑上有2.7和3.6 所以 ...
- python自学第9天,装饰器
装饰器:本质是函数(装饰其它函数) 就是为其它函数添加附加功能 原则:1.不能修改被装饰函数的源代码 2.不能修改被装饰的函数的调用方式 实现装饰器知识储备: 1.函数即变量 2.高阶函数:a.把一个 ...
- idea2018+maven+web新手maven指南
CSDN上的博主详细的很 https://blog.csdn.net/hncu1306602liuqiang/article/details/82356097
- wav文件格式分析与详解
WAV文件是在PC机平台上很常见的.最经典的多媒体音频文件,最早于1991年8月出现在Windows 3.1操作系统上,文件扩展名为WAV,是WaveFom的简写,也称为波形文件,可直接存储声音波形, ...