Linux下nginx配置https协议访问
一、配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module
查看nginx编译参数:/usr/local/nginx/sbin/nginx -V
如下所示:
configure arguments: --prefix=/usr/local/nginx --with-google_perftools_module --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
如果没有--with-http_gzip_static_module这个参数,需要重新编辑nginx
二、防火墙开启https协议默认端口443
vi /etc/sysconfig/iptables #编辑防火墙配置文件,添加以下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
:wq! #保存退出
service iptables restart #重启防火墙
三、创建https证书
确保机器上安装了openssl和openssl-devel
yum install openssl openssl-devel #CentOS使用yum命令安装
mkdir /usr/local/nginx/conf/ssl #创建证书存放目录
cd /usr/local/nginx/conf/ssl #进入目录
创建服务器私钥:openssl genrsa -des3 -out server.key 1024 #根据提示输入证书口令
创建签名请求的证书(CSR):openssl req -new -key server.key -out server.csr #输入上面设置的口令
#根据提示输入相应的信息
Country Name (2 letter code) [XX]:cn #国家
State or Province Name (full name) []:zhejiang #省份
Locality Name (eg, city) [Default City]:hangzhou #城市
Organization Name (eg, company) [Default Company Ltd]:osyunwei #公司
Organizational Unit Name (eg, section) []:sys #部门
Common Name (eg, your name or your server's hostname) []:osyunwei #主机名称
Email Address []:xxx@qq.com #邮箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 #证书请求密钥,CA读取证书的时候需要输入密码
An optional company name []:osyunwei #公司名称,CA读取证书的时候需要输入密码
openssl rsa -in server.key -out server_nopassword.key #对key进行解密
openssl x509 -req -days 365 -in server.csr -signkey server_nopassword.key -out server.crt
#标记证书使用上述私钥和CSR
四、修改nginx配置文件,加载ssl证书
vi /usr/local/nginx/conf/nginx.conf #编辑
listen 80;
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/server_nopassword.key;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
ssl_prefer_server_ciphers on;
fastcgi_param HTTPS $https if_not_empty; #有https协议时自动使用https,否则忽略这个参数。
:wq! #保存退出
service nginx restart #重启nginx
rewrite ^(.*) https://www.osyunwei.com$1 permanent; #可以把http协议重定向到https上面
#301跳转也可以把http协议重定向到https上面
server {
listen 80;
server_name www.osyunwei.com;
return 301 https://$host$request_uri;
}
使用https协议打开网址,如下图所示:
转载于OS运维
Linux下nginx配置https协议访问的更多相关文章
- 【转】Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
- Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
- Linux服务之nginx服务篇四(配置https协议访问)
一.配置nginx支持https协议访问 编译安装nginx的时候需要添加相应的模块--with-http_ssl_module和--with-http_gzip_static_module(可通过/ ...
- windwos下nginx 配置https并http强制跳转https
windwos下nginx 配置https并http强制跳转https 一.首先配置证书文件 申请证书文件,这里就不做详细过程了,直接看证书文件结果. 这是两个证书的关键文件 打开ngxin下con ...
- Tomcat配置https协议访问
Tomcat9配置https协议访问: https://blog.csdn.net/weixin_42273374/article/details/81010203 配置Tomcat使用https协议 ...
- Linux下Nginx配置阿里云 SSL证书实现HTTPS访问
这篇文章主要介绍了nginx配置ssl证书实现https访问的示例 1.服务器系统:Centos 2. 阿里云申请SSL证书 选择“免费版DV SSL”,点击立即购买: 下载证书 列表中找到已签发的证 ...
- linux下nginx配置ssl证书(https)
nginx配置ssl很简单,首先需要两个文件,一个是crt文件,另一个是key文件,如下所示: xxx.crt; #(证书公钥)xxx.key; #(证书私钥) 把这两个文件放到nginx的conf ...
- lnmp之Nginx配置https加密访问
配置lnmp之Nginx网站支持https加密访问 注: 1. 这里拿购买的(pxsnx.pxjy.com)证书来做样例 证书文件共有三个---> (pxsnxg.pxjy.com_ca.crt ...
- Linux下Apache配置HTTPS功能
Apache配置HTTPS功能 转 https://www.cnblogs.com/liaojiafa/p/6028816.html 一.yum 安装openssl和openssl-devel,ht ...
随机推荐
- redis缓存击穿和缓存雪崩
工作中经常会用到redis来做缓存,以防止后台db挂掉.但是db数据一般都在10T以上,不可能把mysql中的数据全部放入redis中,所以一般是将一些热key放入redis中. 缓存击穿 一个请求先 ...
- springboot系列(二) 创建springboot工程
本文转载自:https://www.cnblogs.com/magicalSam/p/7171716.html 简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新 ...
- LAMP源码编译安装
php加速器 XCache 快速而且稳定的PHP opcode缓存,经过严格测试且被大量用于生产环境. 项目地址:http://xcache.lighttpd.net/,收录EPEL源 实现XCach ...
- <转载>c++中new一个二维数组
原文连接 在c++中定义一个二维数组时有多种方式,下面是几种定义方式的说明:其中dataType 表示数据类型,如int byte long... 1.dataType (*num)[n] = n ...
- Octave(控制语句)
for循环遍历 >> v = zeros(,) v = >> v() ans = >> :, v(i) = ^i; end; >> v v = 或者: ...
- nuxt入门
之前一直都是做vue-spa单页面,不利于SEO.而便于SEO的SSR(服务器端渲染)多页应用,可以使用nuxt.js这个框架来实现 (0)nuxt安装 npx create-nuxt-app < ...
- 解决 分布式事务中HRESULT:0x8004D025 错误
最近在开发分布式事务的过程中,碰到 该伙伴事务管理器已经禁止了它对远程/网络事务的支持. (异常来自 HRESULT:0x8004D025)的错误. 后来检查到,原来是数据库服务器的MSDTC 没有设 ...
- eclipse 设置字体高亮
在eclipse中不小心按错了什么键,使得变量的高亮显示没了. 其恢复方式如下: 选择:windows-> preferences->java->Editor->Mark Oc ...
- Educational Codeforces Round 40 (Rated for Div. 2) 954G G. Castle Defense
题 OvO http://codeforces.com/contest/954/problem/G 解 二分答案, 对于每个二分的答案值 ANS,判断这个答案是否可行. 记 s 数组为题目中描述的 a ...
- 出现错误时返回异常 MVC
在使用MVC的时候,会出现异常提醒: 1,当在Controller出现错误的时候,我们可以直接返回,即return view()返回视图. ViewBag.Msg("产品或赠品不存在&qu ...