(1)首先确保机器上安装了openssl和openssl-devel
yum install openssl
yum install openssl-devel
(2)查看nginx是否安装--with-http_ssl_module扩展
查看方式:/usr/local/nginx/sbin/nginx -V
wget https://nginx.org/download/nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module --with-pcre
make && make
(3)创建ssl文件夹:mdir /usr/local/nginx/conf/ssl
进入:cd /usr/local/nginx/conf/ssl
创建证书:
openssl genrsa -des3 -out server.key 1024 (建立服务器私钥,在这个过程中需要输入密码短语,需要记住这个密码)
openssl req -new -key server.key -out server.csr
输入命令以后,需要填写如下内容:
Country Name(国家:中国填写CN)
State or Province Name(区域或是省份:CHONGQING)
Locality Name(地区局部名字:CHONGQING)
Organization Name(机构名称:填写公司名)
Organizational Unit Name(组织单位名称:部门名称)
Common Name(网站域名)
Email Address(邮箱地址)
A challenge password(输入一个密码)
An optional company name(一个可选的公司名称)
输入完这些内容,就会在当前目录生成server.csr文件
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key (对于使用上面的私钥启动具有SSL功能的NGINX)
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt (使用上面的密钥和CSR对证书进行签名)
在本地配置虚拟主机:www.wxsipa.com
windows:C:\Windows\System32\drivers\etc\hosts
(4)配置nginx:
vi /usr/local/nginx/conf/vhosts/test.conf
server
{
listen 80;
listen 443 ssl;
server_name www.wxsipa.com;
index index.php index.html index.htm;
root /home/www/test;
error_log logs/moodle-error.log;
access_log logs/moodle-access.log;
ssl_certificate /usr/local/nginx/conf/ssl/server.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/server.key;
keepalive_timeout 70;
lient_max_body_size 300M;
client_body_buffer_size 1024k;
server_tokens off;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .*\.php?$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
}
重启nginx