各位用户为了找寻关于Nginx实现https网站配置代码实例的资料费劲了很多周折。这里教程网为您整理了关于Nginx实现https网站配置代码实例的相关资料,仅供查阅,以下为您介绍关于Nginx实现https网站配置代码实例的详细内容

https基础 443端口. 用于了一个叫密钥的东西. 不要觉得这些东西您不了解也能实现. 不可能的.

1.先成密钥.咱们直接linux下生成 假设nginx目录为 /usr/local/nginx-1.2.9

接下来

cd /usr/local/nginx-1.2.9/conf/; mkdir ssl; cd ssl; #下面开始创建密钥.如果不熟悉完全不必理会为什么这么做照做就可以了 openssl genrsa -des3 -out server.key 1024;#这一步会让您输入密码. 输入就可以了 下面这步要用到这个密码. 随意 openssl req -new -key server.key -out server.csr;#输入刚才设置的密码后一路回车 cp server.key server.key.org; openssl rsa -in server.key.org -out server.key;#这一步还需要密码的 openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt; #到此生成结束 此时 ssl目录里有一下几个文件 server.crt server.csr server.key server.key.org

2.第二步,咱们建一个站点. 配置文件如下. (如果不会写配置文件的朋友可以参考本论坛)

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 server {   listen    443;   ssl on; #注意路径和文件扩展名   ssl_certificate /usr/local/nginx-1.2.9/conf/ssl/server.crt;   ssl_certificate_key /usr/local/nginx-1.2.9/conf/ssl/server.key;   server_name 域名;   root  网站根目录;   location / {     index index.html index.php;   } #支持PHP   location ~ .php{     include fastcgi_params;         fastcgi_split_path_info ^(.+.php)(.*)$;         fastcgi_param PATH_INFO $fastcgi_path_info;     fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;     fastcgi_pass 127.0.0.1:9000;     fastcgi_index index.php;   } }

好了 nginx -s reload 重启nginx看一下吧. 可以使用https访问了

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/ghjbk/p/7792027.html