一、配置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协议访问的更多相关文章

  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. IDAPython实战项目——DES算法识别

    在CTF的逆向中我们需要的是找到加密的主函数,结合了yara的识别原理,通过对常量数组的引用的查找,一步步递归构建调用树.调用树根部就是可能的密码算法主函数. 由于这种办法需要常量分布于算法的各个步骤 ...

  2. 实现LAMP架构

    LAMP介绍 LAM(M)P: L: linux A: apache (httpd) M: mysql, mariadb M:memcached P: php, perl, python WEB资源类 ...

  3. .NET Core中使用水印

    .NET Core中使用水印 在项目中,我需要给上传的图片添加水印,通过网上查找针对.NET Core 的找到两个方案: 使用 CoreCompat.System.Drawing 及用于非Window ...

  4. TCP/UDP Socket调试工具提供了TCP Server,TCP Client,UDP Server,UDP Client,UDP Group 五种Socket调试方案。

    一.TCP通信测试: 1)   创建TCP Server: 选中左方的TCP Server, 然后点击”创建”按钮,软件弹出监听端口输入框 输入监听端口后,即创建了一个在指定端口上进行监听的TCP S ...

  5. 解决echarts的叠堆折线图数据出现坐标和值对不上的问题

    原文:https://blog.csdn.net/qq_36538012/article/details/88889545 ------------------------------- 说一个小bu ...

  6. PHP批量更新MYSQL中的数据

    原文链接:https://blog.csdn.net/wuming19900801/article/details/62893429 $sql = "update newhouse_clic ...

  7. java 基础:方法调用中的值传递是call by value,并且传递的是参数的值的拷贝,而不是引用

    public class TestExtends { public static void main(String[]args){ int s = 10; System.out.println(Sys ...

  8. Vue入门——v-if和v-show

    v-if 特点:每次都会重新删除或创元素 有较高的切换性能消耗 v-show 特点:每次不会重新进行DOM的删除和创建操作,只是切换了元素的display:none样式 有较高的初始渲染消耗

  9. Oracle自动化安装脚本-part02-亲试ok

     此为网络配置文件  network.conf [PUBLIC-IP] IP-LIST:192.168.7.198,192.168.8.221 HOSTNAME-LIST:mysql-198,RAC2 ...

  10. Mysql中对字符串类型的字段进行数字值排序

    排序字段+0或者*1,类似  Java 把 其他类型转换成字符串 比如 +“”: 一.对普通数字字符串字段排序 -- 方式一 SELECT * FROM xxxxxx WHERE STATUS ' O ...