nginx配置https【转】

本文详细介绍如何在Nginx中启用SSL加密连接,包括编译安装模块、生成证书及密钥、配置Nginx.conf文件等内容。适用于希望保护网站通信安全的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx要实现ssl,在编译时要添加--with-http_ssl_module,如:
./configure --with-http_ssl_module

#cd /usr/local/nginx/conf
#mkdir ssl
#cd ssl
生成一个私有key
# openssl genrsa -des3 -out aoshiwei.com.key 1024
提示输入密码
生成CSR(Certificate Signing Request)文件:
# openssl req -new -key aoshiwei.com.key -out aoshiwei.com.csr
填写证书内容,组织机构、域名等,Common Name填写域名
 
# cp aoshiwei.com.key aoshiwei.com.key.bak
# openssl rsa -in aoshiwei.com.key.bak -out aoshiwei.com.key
# openssl x509 -req -days 365 -in aoshiwei.com.csr -signkey aoshiwei.com.key -out aoshiwei.com.crt

在nginx.conf中添加:
  1. server {  
  2.         ### server port and name ###  
  3.         listen          443 ssl;  
  4.         server_name     member.aoshiwei.com;  
  5.         ssl on;  
  6.    
  7.         ### SSL log files ###  
  8.         access_log      logs/ssl-access.log;  
  9.         error_log       logs/ssl-error.log;  
  10.    
  11.         ### SSL cert files ###  
  12.         ssl_certificate      ssl/aoshiwei.com.crt;  
  13.         ssl_certificate_key  ssl/aoshiwei.com.key;  
  14.         ### Add SSL specific settings here ###  
  15.         keepalive_timeout    60;  
  16.    
  17.         ###  Limiting Ciphers ########################  
  18.         # Uncomment as per your setup  
  19.         #ssl_ciphers HIGH:!ADH;  
  20.         #ssl_perfer_server_ciphers on;  
  21.         #ssl_protocols SSLv3;  
  22.         ##############################################  
  23.         ### We want full access to SSL via backend ###  
  24.         location / {  
  25.                 proxy_pass  http://member.aoshiwei.com;  
  26.                 ### force timeouts if one of backend is died ##  
  27.                 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;  
  28.    
  29.                 ### Set headers ####  
  30.                 proxy_set_header Host $host;  
  31.                 proxy_set_header X-Real-IP $remote_addr;  
  32.                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  33.    
  34.                 ### Most PHP, Python, Rails, Java App can use this header ###  
  35.                 proxy_set_header X-Forwarded-Proto https;  
  36.    
  37.                 ### By default we don't want to redirect it ####  
  38.                 proxy_redirect     off;  
  39.                 }  
  40.       } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值