mkcert生成ssl证书+nginx部署局域网内的https服务访问问题

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

键盘的Win + R键,输入cmd,打开命令窗口
在这里插入图片描述
输入(结果如下图所示)

echo %PROCESSOR_ARCHITECTURE%

回车

在这里插入图片描述
在这里插入图片描述
下载完成后,将下载的exe程序复制到某个目录下。这个目录等下需要用到的。
在这里插入图片描述

2、安装mkcert

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在对应的目录下输入(结果如下图所示)

mkcert-v1.4.4-windows-amd64.exe -install

在这里插入图片描述
会弹出一个安全警告窗口,然后选择是
在这里插入图片描述
选择是之后
在这里插入图片描述

3、测试mkcert是否安装成功

在对应的命令窗口输入(具体看后面的截图)

mkcert-v1.4.4-windows-amd64.exe --help

出现如下截图所示的内容,就说明,mkcert安装成功了
在这里插入图片描述

4、查看CA证书存放位置

输入

mkcert-v1.4.4-windows-amd64.exe -CAROOT

命令。
在这里插入图片描述
我们可以到对应的目录下,看一下对应的目录
在这里插入图片描述

5、打开windows的证书控制台

按住键盘的,“Win键+R键”调出运行框,输入certmgr.msc命令。打开证书控制台。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

6、生成自签证书,可供局域网内使用其他主机访问

在命令窗口中输入(具体看后面的截图)

mkcert-v1.4.4-windows-amd64.exe localhost 127.0.0.1 ::1 192.168.1.1 
# 这个192.168.1.1是我的电脑的地址,这里根据根据自己的电脑ip进行设定

根据自己的需求填写ip可以有多个ip。(如上所示,就使用localhost、127.0.0.1、::1、192.168.1.1)这四个地址,生成对应的证书,也就是这个证书中,是根据这个四个地址生成的。

在IP地址中,::1 是一个特殊的IPv6地址,被称为回环地址(loopback address)。在IPv4中,回环地址是 127.0.0.1。IPv6的回环地址 ::1 与IPv4的 127.0.0.1 在功能上是相似的。

这种地址在本地开发、测试网络服务和应用时非常有用,因为它确保通信不会离开本地机器,从而避免了可能存在的网络延迟或外部干扰。

在这里插入图片描述
在这里插入图片描述
上面截图中生成的那两个,就是我们后面使用nginx部署本地https服务时用到的证书了。

以下是nginx部署https服务相关的内容

到官网下载nginx

到nginx官网(nginx: download)下载nginx,
在这里插入图片描述

使用nginx

下载成功后,将下载的zip包,根据自己的情况,放到对应的目录下,解压。(这里有一点值得注意的是,nginx最好放在非中文目录下,在nginx-1.24.0版本之前,nginx放在有中文的目录下,时无法启动nginx的)因为,我这里使用的是nginx-1.24.0版本,所以放在中文下,也无所谓。但是在项目部署中,还是不建议,放在有中文的目录下,免得出现奇奇怪怪的的问题,省心省力。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在配置的截图后面,有配置的文字内容,这里先截图出来
在这里插入图片描述

nginx配置如下所示


#user nobody;
worker_processes  1;

#error\_log logs/error.log;
#error\_log logs/error.log notice;
#error\_log logs/error.log info;

#pid logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log\_format main '$remote\_addr - $remote\_user [$time\_local] "$request" '
    # '$status $body\_bytes\_sent "$http\_referer" '
    # '"$http\_user\_agent" "$http\_x\_forwarded\_for"';

    #access\_log logs/access.log main;

    sendfile        on;
    #tcp\_nopush on;

    #keepalive\_timeout 0;
    keepalive_timeout  65;

    #gzip on;

    server {
        listen       8088;
        server_name  localhost;

        #charset koi8-r;

        #access\_log logs/host.access.log main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error\_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        # proxy\_pass http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        # root html;
        # fastcgi\_pass 127.0.0.1:9000;
        # fastcgi\_index index.php;
        # fastcgi\_param SCRIPT\_FILENAME /scripts$fastcgi\_script\_name;
        # include fastcgi\_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        # deny all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server\_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}


    # HTTPS server
    #
    #server {
    # listen 443 ssl;
    # server\_name localhost;

    # ssl\_certificate cert.pem;
    # ssl\_certificate\_key cert.key;

    # ssl\_session\_cache shared:SSL:1m;
    # ssl\_session\_timeout 5m;

    # ssl\_ciphers HIGH:!aNULL:!MD5;
    # ssl\_prefer\_server\_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

}


启动nginx

保存好配置之后,返回上一级目录。启动nginx。

这里关于nginx的启动方式不止一种,根据自己的需求看着选择。

启动方式一
在这里插入图片描述
双击之后会有一个一闪而过的窗口,然后就啥都没有了,这个不用管,往文章后面看就可以了。如果是第一次使用,会有一个弹窗,关于是否允许网络访问的,选择允许即可。

启动方式二
在nginx对应的目录下,输入充cmd
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

验证nginx是否启动成功了。

访问:http://localhost:8088/
在这里插入图片描述

停止nginx

因为前面已经启动过了nginx,所以如果要使用nginx部署https服务,就需要停止已经启动的nginx,然后修改nginx相关的配置。上面这一步是为了确认nginx已经安装成功了,可以正常启动。停止nginx的方式也有多种,看自己的选择。
方式一:在任务管理器中停止nginx。
在这里插入图片描述
方式二:使用命令nginx -s stopnginx -s quit停止Nginx。
在这里插入图片描述
方式三:杀死所有nginx进程
随便一个命令窗口,如键盘的 Win + R 键,然后输入cmd,打开命令窗口执行下面两步命令,可以找到和停止所有的nginx进程,这个需要特别注意。这个会停止所有的nginx进程,所以如果,你的电脑中有很多个nginx在使用时,不建议使用这个。

tasklist | findstr nginx
taskkill /IM nginx.exe /F

在这里插入图片描述
测试一下nginx是否已经停止了,访问一下:http://localhost:8088/
在这里插入图片描述

综上所述:建议使用方式二,这样停止nginx,即不影响其他nginx,也可以避免停止错nginx。

配置https服务

在这里插入图片描述
在这里插入图片描述
之后,就是打开nginx.conf文件,配置nginx先关的内容了
在这里插入图片描述

nginx的配置如下所示:(截图后面,有配置文件的说明)
在这里插入图片描述
在上面的截图中,这里的证书名称是可以随便重命名的,只要在重命名的时候,保留对应的后缀就可以了。如当我把证书重命名成:aaa-key.pem、aaa.pem时,在nginx对应的配置位置就需要改成,aaa.pem、aaa-key.pem。就一个名称而已,看着改就行了,不改也可以。


#user nobody;
worker_processes  1;

#error\_log logs/error.log;
#error\_log logs/error.log notice;
#error\_log logs/error.log info;

#pid logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log\_format main '$remote\_addr - $remote\_user [$time\_local] "$request" '
    # '$status $body\_bytes\_sent "$http\_referer" '
    # '"$http\_user\_agent" "$http\_x\_forwarded\_for"';

    #access\_log logs/access.log main;

    sendfile        on;
    #tcp\_nopush on;

    #keepalive\_timeout 0;
    keepalive_timeout  65;

    #gzip on;

    server {
        listen       8088;
        server_name  localhost;

        #charset koi8-r;

        #access\_log logs/host.access.log main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error\_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        # proxy\_pass http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        # root html;
        # fastcgi\_pass 127.0.0.1:9000;
        # fastcgi\_index index.php;
        # fastcgi\_param SCRIPT\_FILENAME /scripts$fastcgi\_script\_name;
        # include fastcgi\_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        # deny all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {


**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618635766)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值