課程涉及:
1) HTTPS安全訪問(wèn)概念介紹
2) HTTPS安全訪問(wèn)配置過(guò)程
3) HTTPS安全頁(yè)面跳轉(zhuǎn)功能
4) blog偽靜態(tài)跳轉(zhuǎn)功能
5) 實(shí)現(xiàn)wordpress https訪問(wèn)結(jié)合負(fù)載均衡
HTTPS安全訪問(wèn)概念介紹
利用傳統(tǒng)HTTP訪問(wèn)網(wǎng)站,安全隱患
- a 無(wú)法保證數(shù)據(jù)機(jī)密性----->http是銘文的。
解決: 利用公鑰和私鑰 對(duì)數(shù)據(jù)進(jìn)行加密 --- 對(duì)稱加密算法(通訊雙方都有鑰匙和鎖頭,傳輸數(shù)據(jù)的時(shí)候用鎖頭鎖住,傳到對(duì)端時(shí),用鑰匙進(jìn)行解密。網(wǎng)站的回復(fù)數(shù)據(jù)包時(shí)也會(huì)將內(nèi)容用鎖頭鎖住。)
b 無(wú)法保證數(shù)據(jù)完整性
解決: 利用公鑰和私鑰 對(duì)數(shù)據(jù)進(jìn)行加密 --- 對(duì)稱加密算法(通訊雙方都有鑰匙和鎖頭)
加密數(shù)據(jù)指紋(特征碼加鎖鎖住) 保證數(shù)據(jù)完整性c 無(wú)法對(duì)用戶身份驗(yàn)證
解決: 利用公鑰和私鑰 對(duì)數(shù)據(jù)進(jìn)行加密 --- 非對(duì)稱加密算法(通訊只有一方有秘鑰對(duì) 第一方只有公鑰)
如何確定第一次訪問(wèn)的網(wǎng)站時(shí)真實(shí)的網(wǎng)站。

通過(guò)查詢CA機(jī)構(gòu)查詢證書的真?zhèn)危總€(gè)網(wǎng)站都會(huì)有CA機(jī)構(gòu)頒發(fā)的真實(shí)證書。
HTTPS安全訪問(wèn)配置過(guò)程
第一個(gè)歷程: 創(chuàng)建私鑰過(guò)程
openssl genrsa -idea -out server.key 2048 (1024-2048)
genrsa --- 指定創(chuàng)建私鑰類型
idea --- 需要給私鑰設(shè)置密碼信息
out --- 進(jìn)行標(biāo)準(zhǔn)輸出
2048 --- 密鑰加密長(zhǎng)度
實(shí)際操作:
[root@web01 ssh_key]# openssl genrsa -idea -out server.key 2048
Generating RSA private key, 2048 bit long modulus
........+++
.......+++
e is 65537 (0x10001)
Enter pass phrase for server.key: ---必須設(shè)置密碼,否則會(huì)報(bào)錯(cuò)。另外,可防止私鑰去申請(qǐng)證書,申請(qǐng)和同網(wǎng)站一樣的證書,會(huì)不安全。
Verifying - Enter pass phrase for server.key:
openssl genrsa -out server.key 2048 --- 私鑰沒(méi)有密碼信息(不安全)
第二個(gè)歷程: 利用私鑰創(chuàng)建證書過(guò)程
申請(qǐng)真正證書:
云主機(jī) --- 域名信息(備案) --- 證書(域名)
系統(tǒng)創(chuàng)建假證:
openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
req --- 創(chuàng)建證書
days --- 指定證書有效期
x509 --- 證書的格式信息
-nodes -newkey --- 去掉私鑰文件密碼信息
-keyout --- 加載私鑰文件
-out --- 輸出生成證書文件(假的)
第三個(gè)歷程: 利用網(wǎng)站服務(wù)加載證書
# 加載ssl crt證書文件存放路徑
Syntax: ssl_certificate file; ---- 加載證書信息
Default: —
Context: http, server
# 加載ssl key私鑰文件存放路徑
Syntax: ssl_certificate_key file; ---- 加載私鑰信息
Default: —
Context: http, server
[root@web01 conf.d]# cat www.conf
server {
listen 443 ssl;---->加載證書
server_name www.oldboy.com;
ssl_certificate /etc/nginx/ssh_key/server.crt;---->也可相對(duì)路徑
ssl_certificate_key /etc/nginx/ssh_key/server.key;
location / {
root /html/www;
index index.php oldboy.jpg index.html index.htm;
}
通過(guò)負(fù)載均衡HTTPS訪問(wèn)
方式一: 全網(wǎng)站證書配置
第一個(gè)歷程: web01 web02 web03 保存證書和私鑰信息
openssl genrsa -idea -out server.key 2048
openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
第二個(gè)歷程: 進(jìn)行nginx配置文件修改
[root@web01 conf.d]# cat www.conf
server {
listen 443 ssl;
server_name www.oldboy.com;
ssl_certificate /etc/nginx/ssh_key/server.crt;
ssl_certificate_key /etc/nginx/ssh_key/server.key;
location / {
root /html/www;
index index.php oldboy.jpg index.html index.htm;
}
第三個(gè)歷程: 修改負(fù)載均衡服務(wù)
openssl genrsa -idea -out server.key 2048
openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
創(chuàng)建證書和密鑰
ssl_certificate /etc/nginx/ssh_key/server.crt;
ssl_certificate_key /etc/nginx/ssh_key/server.key;
upstream default {
server 10.0.0.7:443;
#server 10.0.0.8:443;
server 10.0.0.9:443;
}
server {
listen 443 ssl;
server_name localhost;
include proxy_params;
location / {
proxy_pass https://default;
}
}
方式二: 負(fù)載均衡證書配置
第一個(gè)歷程: 去掉web節(jié)點(diǎn)證書配置
listen 80;
server_name www.oldboy.com;
#ssl_certificate /etc/nginx/ssh_key/server.crt;
#ssl_certificate_key /etc/nginx/ssh_key/server.key;
第二個(gè)歷程: 編寫負(fù)載均衡配置文件
ssl_certificate /etc/nginx/ssh_key/server.crt;
ssl_certificate_key /etc/nginx/ssh_key/server.key;
upstream default {
server 10.0.0.7:80;
#server 10.0.0.8:443;
server 10.0.0.9:80;
}
server {
listen 443 ssl;
server_name localhost;
include proxy_params;
location / {
proxy_pass http://default;
}
}

HTTPS安全頁(yè)面跳轉(zhuǎn)功能
實(shí)現(xiàn)跳轉(zhuǎn)方式一:
rewrite ^/(.*) https://ssl.oldboy.com$1 redirect;
http://ssl.oldboy.com /oldboy/oldboy.html --> https://ssl.oldboy.com/oldboy/oldboy.html
url ^/(.*)uri不管時(shí)什么后面都原封不動(dòng)的輸出----》url進(jìn)行跳轉(zhuǎn)
實(shí)現(xiàn)跳轉(zhuǎn)方式二:
return 302 https://$server_name$request_uri;
http://ssl.oldboy.com /oldboy/oldboy.html -- 302 --- https://ssl.oldboy.com/oldboy/oldboy.html
$server_name $request_uri
方式一: 利用web服務(wù)器實(shí)現(xiàn)跳轉(zhuǎn)
第一個(gè)歷程: 修改web服務(wù)配置文件
server {
listen 80;
server_name www.oldboy.com;
rewrite ^/(.*) https://www.oldboy.com/$1 redirect;
}
server {
listen 443 ssl;
server_name www.oldboy.com;
ssl_certificate /etc/nginx/ssh_key/server.crt;
ssl_certificate_key /etc/nginx/ssh_key/server.key;
location / {
root /html/www;
index index.php oldboy.jpg index.html index.htm;
}
第二個(gè)歷程: 修改負(fù)載均衡配置 ---- >502,有問(wèn)題???
ssl_certificate /etc/nginx/ssh_key/server.crt;
ssl_certificate_key /etc/nginx/ssh_key/server.key;
upstream default {
server 10.0.0.7:80;
#server 10.0.0.8:443;
#server 10.0.0.9:80;
}
server {
listen 443 ssl;
server_name localhost;
include proxy_params;
location / {
proxy_pass https://default;
}
}
server {
listen 80;
server_name localhost;
include proxy_params;
location / {
proxy_pass http://default;
}
}
實(shí)現(xiàn)wordpress網(wǎng)站實(shí)現(xiàn)HTTPs訪問(wèn)
第一個(gè)歷程: 正常訪問(wèn)wordpress頁(yè)面,修改訪問(wèn)域名為https://blog.oldboy.com
wordpress后臺(tái) -- 設(shè)置 -- 常規(guī)
wordpress地址: https://blog.oldboy.com
站點(diǎn)地址: https://blog.oldboy.com
第二個(gè)歷程: 配置web服務(wù)
server {
listen 80;
server_name blog.oldboy.com;
client_max_body_size 5m;
location / {
root /html/blog;
index index.php oldboy.jpg index.html index.htm;
}
location ~ \.php$ {
root /html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param HTTPS on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
第三個(gè)歷程: 配置負(fù)載均衡
ssl_certificate /etc/nginx/ssh_key/server.crt;
ssl_certificate_key /etc/nginx/ssh_key/server.key;
upstream default {
server 10.0.0.7:80;
server 10.0.0.8:443;
server 10.0.0.9:80;
}
server {
listen 80;
server_name www.oldboy.com;
return 302 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name localhost;
include proxy_params;
location / {
proxy_pass http://default;
}
}
wordpress網(wǎng)站實(shí)現(xiàn)偽靜態(tài)功能---->?這種動(dòng)態(tài)態(tài)變?yōu)殪o態(tài)顯示
第一個(gè)步驟:在wordpress后臺(tái)修改頁(yè)面配置
登錄后臺(tái)---設(shè)置---固定鏈接---自定義結(jié)構(gòu)--/%post_id%.html

第二個(gè)步驟:實(shí)現(xiàn)nginx偽靜態(tài)配置
blog.oldboy.com/oldboy.html
第一個(gè)部分:
location / {
try_files $uri $uri/ /index.php?$args==$uri;
去站點(diǎn)找這個(gè)信息 有沒(méi)有這個(gè)目錄 如果都沒(méi)有直接訪問(wèn)偽靜態(tài)的信息。
}
第二個(gè)部分: http://blog.oldboy.com/4.html -- 站點(diǎn)目錄 ---
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
協(xié)議 url不變 變?yōu)楹笈_(tái)配置的
[root@web01 conf.d]# cat blog.conf
server {
listen 80;
server_name blog.etiantian.org;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location / {
root /html/blog;
index index.php index.html;
try_files $uri $uri/ /index.php?$args==$uri;
}
location ~ \.php$ {
root /html/blog;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}