Nginx
使用Nginx配置HTTPS域名证书
1.查看nginx是否有nginx模块
方法1:./nginx -V
方法2:cd objs/
vim ngx_modules.c 查找ssl
如果没有:重新编译配置文件
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_ssl_module
make && make install
2.配置HTTPS
- 把ssl证书*.crt和私钥*.key拷贝到/usr/local/nginx/conf目录中。
- 新增 server 监听 443 端口:
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl_certificate *.crt;
ssl_certificate_key *.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
nginx -t
nginx -s reload