我司的环境是,同一个ip,绑定多个2级域名,访问每个2级域名都要有https(解决单IP多站点 https://域名乱跳网站的问题)
我司采用的是方案5
核心思路:重定向,只是写法不同
一、Nginx安装(略)
安装的时候需要注意加上 --with-http_ssl_module,因为http_ssl_module不属于Nginx的基本模块。
Nginx安装方法:
1 2 |
|
二、生成证书(略)
可以使用openssl生成证书:
可参考:http://www.cnblogs.com/kevingrace/p/5865501.html
比如生成如下两个证书文件(假设存放路径为/usr/local/nginx/cert/):
wangshibo.crt
wangshibo.key
三、修改Nginx配置
server {
listen 443;
server_name www.wangshibo.com;
root /var/www/vhosts/www.wangshibo.com/httpdocs/main/;
ssl on;
ssl_certificate /usr/local/nginx/cert/wangshibo.crt;
ssl_certificate_key /usr/local/nginx/cert/wangshibo.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5; //或者是ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
access_log /var/www/vhosts/www.wangshibo.com/logs/clickstream_ssl.log main;
error_log /var/www/vhosts/www.wangshibo.com/logs/clickstream_error_ssl.log;
if ($remote_addr !~ ^(124.165.97.144|133.110.186.128|133.110.186.88)) { //对访问的来源ip做白名单限制
rewrite ^.*$ /maintence.php last;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
}
}
http访问强制跳转到https
网站添加了https证书后,当http方式访问网站时就会报404错误,所以需要做http到https的强制跳转设置.
---------------一、采用nginx的rewrite方法---------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|