当前位置:   article > 正文

nginx开启https功能_nginx 未启用 hsts 的 url

nginx 未启用 hsts 的 url

http:80

https:443 下边这种协议比http要安全,因为数据传输是经过加密的

当访问http://www.baidu.com的时候,访问的url会跳转到https://www.baidu.com

一.https简介

1.https其实是由两部分组成的:HTTP+SSL/ TLS,也就是在HTTP上有加了一层加密处理信息的模块。服务端和客户端信息传输都会通过TLS进行加密,所以传输的数据都是加密。具体时间如何进行加密,解密,验证的,且看下图

搭建https网站:

1.先安装依赖包

yum -y install porc-devel zlib-devel popt-devel openssl-devel openssl

2.创建nginx用户

useradd -M -s /sbin/nologin nginx

3.安装nginx

  1. wget http://nginx.org/download/nginx-1.20.2.tar.gz
  2. tar zxf nginx-1.20.2.tar.gz -C /usr/local/
  3. ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module --with-pcre && make && make install ##编译安装
  4. ln -s /usr/local/nginx/sbin/ /usr/local/bin/ ####软连接

4.生成证书:

  1. openssl genrsa -des3 -out server.key 1024 ###grnrsa生成证书 ####server.key证书的名字 ####1024字节
  2. Generating RSA private key, 1024 bit long modulus
  3. ....++++++
  4. ...........++++++
  5. e is 65537 (0x10001)
  6. Enter pass phrase for server.key: ####输入密码
  7. Verifying - Enter pass phrase for server.key: ####再次输入密码

5.创建一个证书申请:

  1. openssl req -new -key server.key -out server.key
  2. Enter pass phrase for server.key:
  3. You are about to be asked to enter information that will be incorporated
  4. into your certificate request.
  5. What you are about to enter is what is called a Distinguished Name or a DN.
  6. There are quite a few fields but you can leave some blank
  7. For some fields there will be a default value,
  8. If you enter '.', the field will be left blank.
  9. -----
  10. Country Name (2 letter code) [XX]:BJ ##哪个国家
  11. State or Province Name (full name) []:BJ ##哪个市区
  12. Locality Name (eg, city) [Default City]:BJ ##默认城市
  13. Organization Name (eg, company) [Default Company Ltd]:BDGJ ##公司名称
  14. Organizational Unit Name (eg, section) []:IT ##单位名称
  15. Common Name (eg, your name or your server's hostname) []:www.benet.com ##服务器主机名等
  16. Email Address []:
  17. Please enter the following 'extra' attributes
  18. to be sent with your certificate request
  19. A challenge password []:
  20. An optional company name []:

其他默认回车 

6.备份一份服务器密钥

cp server.key server.key.org

7.去除文件口令

  1. [root@localhost ~]# openssl rsa -in server.key.org -out server.keyEnter pass phrase for server.key.org: ##输入密码
  2. writing RSA key

8.生成证书文件

  1. [root@localhost ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  2. Signature ok
  3. subject=/C=BG/ST=BG/L=BG/O=BG/OU=qwe/CN=qwe/emailAddress=qwe
  4. Getting Private key
  5. ##证书以.crt结尾的
  6. ##x509是证书的格式
  7. ##-req 申请的意思
  8. ##-days 365 生效一年
  9. ##-in server.csr 指定证书申请文件
  10. ##-signkey server .key 指定私钥
  11. ##-out 输出证书文件

9.开始修改配置文件

  1. server {
  2. listen 443 default ssl; ##默认ssl
  3. ssl_certificate ssl/server.crt; ##指定证书文件
  4. ssl_certificate_key ssl/server.key; ##指定私钥文件
  5. #ssl on; ##nginx版本大>1.15.就不用写
  6. server_name www.benet.com;
  7. location / {
  8. root html;
  9. index index.html index.htm;
  10. }
  11. }

10.创建目录mkdir -p /usr/local/nginx/conf/ssl

将证书与私钥放进去cp server.crt server.key /usr/local/nginx/conf/ssl

重启服务

11.但是访问http:的话会找不到网页,再写一个访问www.benet.com的时候全部都给https://

  1. server {
  2. listen 80;
  3. server_name www.benet.com;
  4. rewrite ^(.*) https://$host$1 permanent;
  5. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/640027
推荐阅读
相关标签
  

闽ICP备14008679号