- Published on
nginx快速安装阿里云SSL并且做跳转
- Authors
- Name
- Hansuku
安装 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.htm
server_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 ^(.*)$ <a href="https://$host$1">https://$host$1</a> permanent;
启动 nginx
/usr/local/nginx/sbin/nginx
netstat -anp
查看 443 端口和 80 端口是否正常被 nginx listen url 输入网址测试 完成。