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 ...
随机推荐
- 安卓直连SQLSEVER数据库
1.导入连接SQLSEVER的jar包:可以支持android的SQL驱动(如:jtds-1.2.7.jar) 2.编写连接数据库的工具类 import java.lang.reflect.Field ...
- linux centos Supervisor守护.netcore进程安装配置
场景:当部署完.netcore程序后 使用dotnet xx.dll 后可以运行,但关闭shell或隔断时间会自动断开,此时部署的.netcore程序就不能访问了,此时需要用到Supervisor了 ...
- haproxy??
HAProxy是一个使用C语言编写的自由及开放源代码软件,其提供高可用性.负载均衡,以及基于TCP和HTTP的应用程序代理. HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保 ...
- Linux学习之九-Linux系统定时任务
Linux系统定时任务 在一些实际工作中需要机器在某个时间自动执行某个任务,不需要人为在此时刻参与,可以建立一个定时任务. crond 服务是linux下用来周期性的执行某种任务或等待处理某些事件的一 ...
- Linux学习之八-配置FTP连接Linux服务器
配置ftp连接Linux服务器 通过配置ftp服务器,可以实现局域网内共享文件,甚至不同用户具有不同权限,需要的工具有Windows平台ftp客户端FileZilla(免费开源) 下载地址:https ...
- mongodb的基本操作之数据删除
删除操作使用remove进行,数据的删除与查询类似,接受一个参数,与查询不同的是,为了防止误操作,删除操作不允许不传参数 比如 db.test_collection.remove() 会报错 Erro ...
- [ 转载 ] vue.js面试题一
转载自:https://www.cnblogs.com/aimeeblogs/p/9501490.html 如有侵权 联系删除 Vue.js面试题整理 一.什么是MVVM? MVVM是Model-Vi ...
- 二分法:从一个只包含数字的list中查找某个数
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017/4/10 19:03 # @Author : MnCu # @Site : # ...
- 模块讲解---numpymo模块,matplotlib模块,pandas模块
目录 numpy模块 matplotlib模块 pandas模块 numpy模块 numpy模块:用来做数据分析,对numpy数组(既有行又有列)--矩阵进行科学运算 在使用的时候,使用方法与其他的模 ...
- //点击按钮加减音频音量到最小会出现bug什么意思???
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...