server {
listen 443 ssl;
server_name www.xxxxweb.cn xxxxweb.cn; //此处填写域名,多个域名直接用空格
root /mnt/wwwroot/web; //网站路径
ssl on;
ssl_certificate 2142222240950154.pem; //证书路径
ssl_certificate_key 2142222240950154.key; //证书路径
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 / {
index index.html index.htm index.php;
#autoindex on;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location = /404.html {
root html;
}
error_page 403 404 500 501 502 503 504 /404.html;
}
1.2 Nginx开启SSL模块
切换到源码包:
1
|
cd /usr/local/src/nginx-1.11.3
|
查看nginx原有的模块
1
|
/usr/local/nginx/sbin/nginx -V
|
在configure arguments:后面显示的原有的configure参数如下:
1
|
--prefix=/usr/local/nginx --with-http_stub_status_module
|
那么我们的新配置信息就应该这样写:
1
|
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
|
运行上面的命令即可,等配置完
配置完成后,运行命令
这里不要进行make install,否则就是覆盖安装
然后备份原有已安装好的nginx
1
|
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
|
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
1
|
cp ./objs/nginx /usr/local/nginx/sbin/
|
然后启动nginx,仍可以通过命令查看是否已经加入成功
1
|
/usr/local/nginx/sbin/nginx -V
|
Nginx 配置Http和Https共存
1
2
3
4
5
6
7
8
9
|
server {
listen 80 default backlog=2048;
listen 443 ssl;
server_name wosign.com;
root / var /www/html;
ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .Key;
}
|
把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
Nginx 配置SSL安全证书重启避免输入密码
可以用私钥来做这件事。生成一个解密的key文件,替代原来key文件。
1
|
openssl rsa - in server.key - out server.key.unsecure
|
Nginx SSL性能调优
1
2
3
4
5
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on ;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
|