- 安装PCRE和ZLIB nginx依赖包
yum -y install pcre pcre-devel
yum install -y zlib-devel
- 下载nginx源码包
wget http://nginx.org/download/nginx-1.6.2.tar.gz - 解压nginx源码包
tar -xvzf nginx-1.6.2.tar.gz - 配置nginx openssl的源码包位置是需要解压选择的 首先切换到nginx-1.6.2目录
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-openssl=/usr/local/openssl-0.9.8zg - 安装源码
make
make install - 使用阿里云的服务器不需要自己生成一个openssl 但是保险起见还是需要进行配置
openssl req -new -x509 -nodes -out server.crt -keyout server.key - 到阿里云官网下载ssl证书上传到nginx的conf目录下
- 配置nginx的nginx.conf
server {
listen 443;ssl on;root html;index index.html index.htmserver_name localhost;ssl_certificate cert/214238956480054.pem; #这里需要写绝对路径ssl_certificate_key cert/214238956480054.key; #这里需要写绝对路径ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_prefer_server_ciphers on;location / {root html;index index.html index.htm;}}
开启了443端口后,需要把80端口http强制跳转到443-https
给80端口{}内加上
rewrite ^(.*)$ https://$host$1 permanent; 重写入URL跳转
- 启动nginx
/usr/local/nginx/sbin/nginx - netstat -anp查看443端口和80端口是否正常被nginx listen
- url输入网址测试 完成
本文由
Hansuku 创作,除注明转载/出处外,均为本站原创,转载前请务必署名
最后编辑时间为: 2017-11-06 10:42 Monday