配置站点使用 https,并且将 http 重定向至 https。
1. nginx 的 ssl 模块安装查看 nginx 是否安装 http_ssl_module 模块,如果出现 configure arguments: --with-http_ssl_module, 则已安装(下面的步骤可以跳过,进入 nginx.conf 配置)。
$ /usr/local/nginx/sbin/nginx -V
配置 ssl 模块
$ cd nginx-1.14.1 $ ./configure --prefix=/usr/local/nginx --with-http_ssl_module
使用 make 命令编译(使用make install会重新安装nginx),此时当前目录会出现 objs 文件夹。
用新的 nginx 文件覆盖当前的 nginx 文件。
$ cp ./objs/nginx /usr/local/nginx/sbin/
再次查看安装的模块(configure arguments: --with-http_ssl_module说明ssl模块已安装)。
$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.1
…
configure arguments: –with-http_ssl_module
ssl证书文件(server.pem、server.key)放在/data/cert/目录下,nginx.conf配置如下:
server {
listen 5000 ssl;
#ssl证书的pem文件路径
ssl_certificate /data/cert/server.pem;
#ssl证书的key文件路径
ssl_certificate_key /data/cert/server.key;
location / {
root D:webPage;
#root D:gitcodeWebbase-js;
#autoindex on;
}
}
3. 重启Nginx
nginx -t nginx -s reload



