网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事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 stop
或nginx -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行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**