nginx配置ssl

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx配置ssl相关的知识,希望对你有一定的参考价值。

vim /usr/local/nginx/conf/vhost/ssl.conf//加入如下内容
server
{
listen 443;
server_name aming.com;
index index.html index.php;
root /data/wwwroot/aming.com;
ssl on;
ssl_certificate aminglinux.crt;
ssl_certificate_key aminglinux.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}
-t && -s reload //若报错unknown directive “ssl” ,需要重新编译nginx,加上--with-http_ssl_module
mkdir /data/wwwroot/aming.com
echo “ssl test page.”>/data/wwwroot/aming.com/index.html
编辑hosts,增加127.0.0.1 aming.com
/etc/init.d/nginx restart
netstat -lnpt
LISTEN 1722/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 57833/nginx: master

curl https://aming.com/
浏览器访问:
技术分享图片
错误!!
/usr/local/nginx/sbin/nginx -t
nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:185
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
是因为之前编译很简单的参数:
/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
configure arguments: --prefix=/usr/local/nginx
解决办法:
cd /usr/local/src/nginx-1.12.2
./configure --help|grep ssl
--with-http_ssl_module
./configure --prefix=/usr/local/nginx/ --with-http_ssl_module
make&&make install
/usr/local/nginx/sbin/nginx -V
configure arguments: --prefix=/usr/local/nginx/ --with-http_ssl_module

以上是关于nginx配置ssl的主要内容,如果未能解决你的问题,请参考以下文章

Nginx实现HTTP强制跳转HTTPS

nginx 更改配置文件后 需要重启吗

nginx 如何检测配置文件的正确性

nginx启动与配置

nginx配置

Nginx主配置参数详解,Nginx配置网站