首先生成證書 或者 購買證書
這裏我們使用阿里雲的證書,可以免費使用一年
配置方法的機票:
https://mp.csdn.net/postedit/86541664
nginx 搭建:
下載nginx
wget http://nginx.org/download/nginx-1.12.0.tar.gz
解壓 安裝
chmod u+x nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
cp -r nginx-1.12.0 /usr/local/nginx-1.12.0
rm -rf nginx-1.12.0
yum install pcre*
yum install -y zlib-devel
yum -y install openssl openssl-devel
./configure --with-http_ssl_module
make
make install
nginx文件在當前文件夾的 objs文件夾下。
配置文件在 conf文件夾下。
將阿里雲的配置文件添加的 nginx.conf 配置文件中
server {
listen 443;
server_name localhost;
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/1753957_openglobal.cn.pem;
ssl_certificate_key cert/1753957_openglobal.cn.key;
ssl_session_timeout 5m;
ssl_ciphers xxxxxxxxxxxxxx;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
server_name 可以配置用戶域名
然後 到objs文件夾下運行命令
./nginx -t
./nginx -s reload
由於免費證書,有的瀏覽器是不認得。
錯誤信息:
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
配置完畢。