此文章是 PHPhub 部署 HTTPs 的笔记, 有很多外链, 这些外链大多是基本知识, 请认真阅读.
HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。
更多基本介绍请查阅:
需要弄清楚的几个问题:
泛域名 SSL 证书 (Wildcard Domain SSL Certificates)
一个大概流程如下:
mkdir -p /etc/nginx/ssl/phphub cd /etc/nginx/ssl/PHPhub
openssl genrsa -out PHPhub.orig 2048
运行
openssl req -new -key phphub.orig -out PHPhub.csr
输出, 需要填写内容:
You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:BeiJing Locality Name (eg, city) []:BeiJing Organization Name (eg, company) [Internet Widgits Pty Ltd]:The EST Group Organizational Unit Name (eg, section) []:Dev Common Name (e.g. server FQDN or YOUR name) []:*.PHPhub.org // ----------注意这个地方要认真填写 Email Address []: emailaddress @ gmail.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: ----------注意不填写---------- An optional company name []: ----------注意不填写----------
openssl rsa -in phphub.orig -out PHPhub.key
至此文件夹里面有 三个文件:
root@localhost:/etc/nginx/ssl/phphub# tree . ├── ikbcity.csr ├── phphub.key └── PHPhub.orig
购买细节这里省去, 需要注意的是要认准比较权威的认证机构购买...
购买成功后会给你发两个证书 server.crt 和 server.intermediate.crt, 生成最终的 server.chained.crt
cat server.crt server.intermediate.crt > PHPhub.crt
此文件就可以和上面生成的 key 文件一起用来配置 nginx 了:
ssl_certificate /etc/nginx/ssl/phphub/phphub.crt; ssl_certificate_key /etc/nginx/ssl/phphub/PHPhub.key;
链接:
server { listen 80; listen 443 ssl; server_name example.com; if ($scheme = http) { return 301 HTTPs://$server_name$request_uri; } .... }
X-Powered-By
headerfastcgi_hide_header X-Powered-By;
server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
其他参照此 Gits:Nginx config on Gits
一般都会出现 cdn 服务器无法访问 HTTPs 源服务器的问题, 可以使用专门的域名static.PHPhub.org
来解决, 此域名专门用来输送静态内容:
server { listen 80; server_name static.phphub.org; root /var/www/PHPhub/public; location ~* .(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|exe|html|htm|txt|css|js) { add_header Cache-Control public; add_header Cache-Control must-revalidate; expires 7d; } location / { deny all; } }
可以利用SSL Server Test -- 安全测试工具去测试下你的 HTTPS 是否够安全.
附上PHPhub 的 test