//環境介紹
html
1.nginx服務器:10.10.54.157nginx
2.配置nginx服務器,當監聽到來自客戶端www.zijian.com:80請求時,轉到10.10.54.150:1500這個web服務器上web
3.配置nginx服務器支持ssl加密傳輸協議shell
//生成nginx服務器須要的證書文件apache
1.建立網站證書存放目錄 shell> mkdir /usr/local/nginx/conf/ssl shell> cd /usr/local/nginx/conf/ssl 2.製做CA證書 shell> openssl genrsa -des3 -out ca.key 2048 shell> openssl req -new -x509 -days 7305 -key ca.key -out ca.crt 3.生成nginx服務器所需證書,並用CA簽名 shell> openssl genrsa -des3 -out client.key 1024 shell> openssl req -new -key client.key -out client.csr shell> openssl x509 -req -in client.csr -out client.pem -signkey client.key -CA ca.crt -CAkey ca.key -CAcreateserial -days 3650 4.查看證書文件 shell> pwd /usr/local/nginx/conf/ssl shell> ls ca.crt ca.key ca.srl client.csr client.key client.pem
//配置nginx支持ssl傳輸協議vim
shell> vim /usr/local/nginx/conf/nginx.conf ------------------------------------------------ user apache apache; worker_processes 2; error_log logs/error_nginx.log; 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_nginx.log main; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; server { listen 443; server_name www.zijian.com; charset uft-8; access_log logs/www.access.log main; root /var/www/html; location / { index index.html index.htm; } ssl on; ssl_certificate /usr/local/nginx/conf/ssl/client.pem; ssl_certificate_key /usr/local/nginx/conf/ssl/client.key; } } -------------------------------------------------------- #上面的配置只支持https://www.zijian.com 訪問,由於監聽端口只開了443端口,普通的http協議的80端口並未開放 #要開放http和https,再加上下面這一條server ------------------------------------------------ server { listen 80; server_name www.zijian.com; charset uft-8; access_log logs/www.access.log main; root /var/www/html; location / { proxy_pass http://10.10.54.150:1500; } } #當用戶使用http協議瀏覽該網站時,自動跳轉到10.10.54.150:1500上 ------------------------------------------------