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

  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. 使用WinDbg内核调试[转]

    Technorati 标签: windbg,内核调试 WINDOWS调试工具很强大,但是学习使用它们并不容易.特别对于驱动开发者使用的WinDbg和KD这两个内核调试器(CDB和NTSD是用户态调试器 ...

  2. Transformer模型总结

    Transformer改进了RNN最被人诟病的训练慢的缺点,利用self-attention机制实现快速并行. 它是由编码组件.解码组件和它们之间的连接组成. 编码组件部分由一堆编码器(6个 enco ...

  3. hive-server 启动失败问题小记

    Unable to instantiate using constructor(MetricRegistry, HiveC onf) for reporter org.apache.hadoop.hi ...

  4. c 判断一个字符是否为字母

    #include <stdio.h> #include <wctype.h> int main () { ; wchar_t str[] = L"C++"; ...

  5. CodeIgniter启用缓存和清除缓存的方法

    Codeigniter支持缓存技术,以达到最快的速度.尽管CI已经相当高效了,但是网页中的动态内容.主机的内存CPU和数据库读取速度等因素直接影响了网页的加载速度.依靠网页缓存,你的网页可以达到近乎静 ...

  6. box-sizing Bootstrap

    https://getbootstrap.com/docs/4.0/getting-started/introduction/#box-sizing Box-sizing For more strai ...

  7. centos-Hadoop集群 安装同步时间

    1.安装 yum search cache ntpdate xcall.sh "yum install -y ntpdate.x86_64" 2.同步 xcall.sh " ...

  8. 2.基于AOP自定义注解Annotation的实现

    上一篇中分析了AOP的实现原理, 总结为: 判断对象是否需要被代理?@Aspect注解的实现是根据切入点表达式 代理之后需要做什么,就是那些通知,本质上是实现了MethodInterceptor的拦截 ...

  9. ContentProvider 共享数据

      onCreate 其它应用第一次访问时被调. insert 外部应用使用此方法添加数据. delete 外部应用使用此方法删除数据. update 外部应用使用此方法更新数据. query 外部应 ...

  10. 改进后的socket轮子,欢迎挑战

    运行环境.net core2.1 下载地址