centos7通过nginx搭建SSL
今天给大家带来的是一篇关于通过nginx搭建HTTPS访问转跳后端HTTP的教程,部署方式如下:
安装基础组件
yum -y isntall firewalld
yum -y install gcc gcc-c++
yum -y install pcre-devel
yum -y install zlib-devel
yum -y install openssl openssl-devel
1
2
3
4
5
下载源码与编译
下载与代码(假设当前在 ~/ 目录下)
wget https://nginx.org/download/nginx-1.12.2.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
1
2
解压
cd /opt
tar zxf nginx-1.12.2.tar.gz
tar zxf openssl-1.0.2n.tar.gz
1
2
3
编译前配置,让nginx支持ssl_module与openssl
cd nginx-1.12.2
./configure --with-http_ssl_module --with-openssl=/opt/openssl-1.0.2n
1
2
编译
make
make install
1
2
安装完成后的nginx路径是: /usr/local/nginx
配置环境
到腾讯云申请证书(自创建证书参看网上其他资料)
把nginx目录下的2个文件复制到 /usr/local/nginx/conf 目录下
配置nginx
vim /usr/local/nginx/conf/nginx.conf
1
在nginx.conf中增加HTTP/HTTPS配置
upstream tomcat {
server 127.0.0.1:9081 fail_timeout=0; #后端服务地址
}
server {
listen 443;
ssl on;
server_name host.httpsDomain.com; #申请证书的域名
ssl_certificate 1_host.httpsDomain.com_bundle.crt; #证书压缩包中nginx文件夹下crt文件,相对路径是在 [/usr/local/nginx/conf]
ssl_certificate_key 2_host.httpsDomain.com.key; #证书压缩包中nginx文件夹下crt文件,相对路径是在 [/usr/local/nginx/conf]
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3; #指定SSL服务器端支持的协议版本
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; #指定加密算法
ssl_prefer_server_ciphers on; #在使用SSLv3和TLS协议时指定服务器的加密算法要优先于客户端的加密算法
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
# note, there is not SSL here! plain HTTP is used
proxy_pass http://tomcat;
}
}
server {
listen 80;
server_name host.httpsDomain.com; #http访问入口
location / {
rewrite ^ https://$http_host$request_uri? permanent; #强制跳转到HTTPS上
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
保存退出
:wq
1
启动nginx
#启动
/usr/local/nginx/sbin/nginx
#重启
/usr/local/nginx/sbin/nginx -s reload
#关闭
/usr/local/nginx/sbin/nginx -s stop
1
2
3
4
5
6
7
8
9
配置防火墙
把firewalld注册成服务并启动
systemctl enable firewalld
systemctl start firewalld
1
2
允许TCP协议下的 80,443 端口 暴露到互联网
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
1
2
3
运行测试
检查防火墙端口
firewall-cmd --list-ports
#看看输出有没有80/tcp与443/tcp
1
2
PS:如果用的是用阿里云/腾讯云,则还需要到XX云控制台检查安全策略组是否开放了TCP下的80与443
检查nginx服务
ss -ntlp | grep nginx
#确认一下 80/tcp 跟 443/tcp 是否被nginx所使用
1
2
浏览器测试
如果大家有什么问题或建议,欢迎留言 ^_^
centos7通过nginx搭建SSL的更多相关文章
- CentOS7下Nginx搭建反向代理,并使用redis保存session
1.启动两个tomcat,端口分别为8080,8081 2.配置nginx,vim /usr/local/nginx/conf/nginx.conf 添加如下配置: 3.启动nginx或热加载 启动: ...
- Centos7 下nginx 搭建文件图片服务器
现在服务器部署nginx yum install -y epel-release yum install nginx -y 安装完成之后 访问ip 由此可见nginx服务是可用的 修改nginx的配置 ...
- 部署文档(centos7.x\nginx\mysql5.6\jdk1.8\ssl\jboot)
部署文档(centos7.x\nginx\mysql5.6\jdk1.8\ssl\jboot) 1.基础环境********************************************** ...
- [转] Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
一.HTTPS 是什么? 根据维基百科的解释: 超文本传输安全协议(缩写:HTTPS,英语:Hypertext Transfer Protocol Secure)是超文本传输协议和SSL/TLS的组合 ...
- Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
一.HTTPS 是什么? 根据维基百科的解释: 超文本传输安全协议(缩写:HTTPS,英语:Hypertext Transfer Protocol Secure)是超文本传输协议和SSL/TLS的组合 ...
- https搭建:ubuntu nginx配置 SSL证书
HTTPS 是什么? 根据维基百科的解释: 超文本传输安全协议(缩写:HTTPS,英语:Hypertext Transfer Protocol Secure)是超文本传输协议和SSL/TLS的组合,用 ...
- Centos7.2下Nginx配置SSL支持https访问(站点是基于.Net Core2.0开发的WebApi)
准备工作 1.基于nginx部署好的站点(本文站点是基于.Net Core2.0开发的WebApi,有兴趣的同学可以跳http://www.cnblogs.com/GreedyL/p/7422796. ...
- centos7.x下环境搭建(五)—nginx搭建https服务
https证书获取 十大免费SSL证书 https://blog.csdn.net/ithomer/article/details/78075006 如果我们用的是阿里云或腾讯云,他们都提供了免费版的 ...
- [python][nginx][https] Nginx 服务器 SSL 证书安装部署
目录 前言 1 申请证书 2 Nginx 服务器 SSL 证书安装部署 2.1.准备 Nginx 环境 2.2 证书部署 2.3 Nginx 配置 3 最后 参考链接 前言 博主博客中的图片,使用的是 ...
随机推荐
- django csrf token添加
#views.py from django.shortcuts import render_to_response, RequestContext from django.views.decorato ...
- Jenkins实现简单的CI功能
步骤一:安装JDK.Tomcat,小儿科的东西不在此详细描述 步骤二:下载安装Jenkins下载链接:https://jenkins.io/download/ 步骤三:将下载的jenkins.war部 ...
- Pycharm安装并配置jupyter notebook
Pycharm安装并配置jupyter notebook Pycharm安装并配置jupyter notebook 一: 安装命令jupyter: pip install jupyter 如果缺少依赖 ...
- 测试报告_HTMLTestRunner.py
(1)模板1下载路径: 链接:https://pan.baidu.com/s/1SydXpWwQd5vDpGlzzhXLfA提取码:3ifp (2)模板二下载路径: 链接:https://pan.ba ...
- 数据库升级到mysql5.7出现的1067 - Invalid default value for '字段名' (docker版)
docker run -d --name xxx mysql:5.7 docker container cp xxx:/etc/mysql/mysql.conf.d . // 取出mysql中的配 ...
- LINUX配置过程记录(二) 工具安装
安装谷歌游览 sudo apt-get update sudo apt-get install google-chrome-stable Ubuntu 16.04下源码安装Catkin https:/ ...
- VUE 简单属性操作
在main.js内配置路由及相应模板 import Vue from 'vue' import App from './App' // 引入router路由 import Router from 'v ...
- vue 绑定样式的几种方式
vue 绑定样式 对象语法 1.v-bind:class设置一个对象,动态切换class <div :class="{'active':isActive}">xxx&l ...
- 创建pandas和sqlalchemy的j交互对象,方便于日常的数据库的增删改查(原创)
#导入第三方库sqlalchemy的数据库引擎 from sqlalchemy import create_engine #导入科学计算库 import pandas as pd #导入绘图库 imp ...
- random使用方法
random.random() 没有参数,选择0到1之间的随机浮点数 random.uniform(a, b) 生成指定范围内的随机浮点数如果a.b哪个大那个小都没关系,生成的都是在小的与大的之间的随 ...