一、配置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 []:[email protected] #邮箱

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;

fastcgi_param HTTPS $https if_not_empty; #有https协议时自动使用https,否则忽略这个参数。

:wq! #保存退出

service nginx restart #重启nginx

rewrite ^(.*) https://www.osyunwei.com$1 permanent; #可以把http协议重定向到https上面

使用https协议打开网址,如下图所示:

至此,Linux下nginx配置https协议访问完成。

【转】Linux下nginx配置https协议访问的方法的更多相关文章

  1. Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  2. Linux下nginx配置https协议访问

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  3. Linux服务之nginx服务篇四(配置https协议访问)

    一.配置nginx支持https协议访问 编译安装nginx的时候需要添加相应的模块--with-http_ssl_module和--with-http_gzip_static_module(可通过/ ...

  4. windwos下nginx 配置https并http强制跳转https

    windwos下nginx  配置https并http强制跳转https 一.首先配置证书文件 申请证书文件,这里就不做详细过程了,直接看证书文件结果. 这是两个证书的关键文件 打开ngxin下con ...

  5. Tomcat配置https协议访问

    Tomcat9配置https协议访问: https://blog.csdn.net/weixin_42273374/article/details/81010203 配置Tomcat使用https协议 ...

  6. Linux下Nginx配置阿里云 SSL证书实现HTTPS访问

    这篇文章主要介绍了nginx配置ssl证书实现https访问的示例 1.服务器系统:Centos 2. 阿里云申请SSL证书 选择“免费版DV SSL”,点击立即购买: 下载证书 列表中找到已签发的证 ...

  7. linux下nginx配置ssl证书(https)

    nginx配置ssl很简单,首先需要两个文件,一个是crt文件,另一个是key文件,如下所示: xxx.crt;  #(证书公钥)xxx.key; #(证书私钥) 把这两个文件放到nginx的conf ...

  8. lnmp之Nginx配置https加密访问

    配置lnmp之Nginx网站支持https加密访问 注: 1. 这里拿购买的(pxsnx.pxjy.com)证书来做样例 证书文件共有三个---> (pxsnxg.pxjy.com_ca.crt ...

  9. Linux下Apache配置HTTPS功能

    Apache配置HTTPS功能  转 https://www.cnblogs.com/liaojiafa/p/6028816.html 一.yum 安装openssl和openssl-devel,ht ...

随机推荐

  1. CSS3_边框属性之圆角

    一.border-radius是向元素添加圆角边框: border-radius的值不仅能用px单位,你还可以用百分比或者em,但兼容性目前还不太好.(都不能是负值) 1.border-radius ...

  2. x265

    1.编译库 https://bitbucket.org/multicoreware/x265/src/tip/build/README.txt?at=default 2.无法定位程序输入点x265_e ...

  3. easyui-datebox 只显示年月

    $(function () { $('#niandu').datebox({ onShowPanel: function () {//显示日趋选择对象后再触发弹出月份层的事件,初始化时没有生成月份层 ...

  4. 探究requestDisallowInterceptTouchEvent失效的原因

    昨天在用requestDisallowInterceptTouchEvent的时候,发如今设置了requestDisallowInterceptTouchEvent(true)之后,父View的onI ...

  5. CRLF CSRF XSS

    http://baike.baidu.com/link?url=BXWN2I6J23thrrm6JoEnAYvmNqp83llyaydaj5RYkq--tuJKSFuMuDMIoTPnKjthRUm3 ...

  6. ios开发中的toll-free bridged

    所谓的Toll-free bridging是说您可以在某个框架的方法或函数 同时使用Core Foundatio和Foundation 框架中的某些类型. 很多数据类型支持这一特性,其中包括群体和字符 ...

  7. Sql Server判断某列字段是否为空或判断某列字段长度

    1.用is null 和 is not null来判断字段是否为空. 2.用len()函数来判断字段长度.

  8. Mongoose学习参考文档

    一.快速通道 1.1 名词解释 Schema : 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力 Model : 由Schema发布生成的模型,具有抽象属性和行为的数据库操作对 Entit ...

  9. 默认选择radio的第一个

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Hive的Security配置

    为了更好地使用好Hive,我将<Programming Hive>的Security章节取出来,翻译了一下. Hive还是支持相当多的权限管理功能,满足一般数据仓库的使用. Hive由一个 ...