0
点赞
收藏
分享

微信扫一扫

nginx、php本地配置https

yongxinz 2022-07-12 阅读 103


​需要安装openssl,如果你已经安装了git,那就可以直接在git bash里面运行openssl命令​​。

1. 使用openssl生成密钥privkey.pem:

openssl genrsa -out privkey.pem 1024/2038

2. 使用密钥生成证书server.pem:

openssl req -new -x509 -key privkey.pem -out server.pem -days 365

3. 证书信息可以随便填或者留空,只有Common Name要根据你的域名填写。

以我的个人网站为例:

Common Name (e.g. server FQDN or YOUR name) []: 51kidtest.com

4.修改nginx配置文件

server {
listen 443;
server_name 51kidtest.com;
ssl on;
ssl_certificate C:\Users\server.pem;
ssl_certificate_key C:\Users\privkey.pem;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

root D:\phpStudy\WWW\KidWebV1.1\public;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

5.验证配置,重启nginx

nginx.exe -t
nginx.exe

nginx、php本地配置https_nginx

6.配置host,打开host文件,路径如下:

C:\Windows\System32\drivers\etc\host

另起一行加入:

127.0.0.1   51kidtest.com

验证成果的时候到了:

7、验证域名是否指向本地:

ping 51kidtest.com

nginx、php本地配置https_php_02

8、访问​​https://51kidtest.com/​​查看效果:

nginx、php本地配置https_nginx_03

9、兼容http访问,但是直接重定向到https:

server {
listen 80;
server_name 51kidtest.com;
#告诉浏览器有效期内只准用 https 访问
add_header Strict-Transport-Security max-age=15768000;
#永久重定向到 https 站点
return 301 https://$server_name$request_uri;
}

大功告成!

错误解决:
1、首先检查nginx是否安装了openssl模块:

\nginx.exe -V

nginx、php本地配置https_php_04


举报

相关推荐

nginx 配置https

nginx配置https

Nginx配置HTTPS

Nginx HTTPS配置

Nginx 配置 HTTPS 证书

Nginx配置https证书

0 条评论