1、Nginx安裝(略)
安裝的時候須要注意加上 --with-http_ssl_module,由於http_ssl_module不屬於Nginx的基本模塊。
Nginx安裝方法:php
1html 2nginx |
|
2、生成證書(略)
可使用openssl生成證書:
可參考:http://www.cnblogs.com/kevingrace/p/5865501.html
好比生成以下兩個證書文件(假設存放路徑爲/usr/local/nginx/cert/):
wangshibo.crt
wangshibo.keysession
3、修改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;ui
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;url
if ($remote_addr !~ ^(124.165.97.144|133.110.186.128|133.110.186.88)) { //對訪問的來源ip作白名單限制
rewrite ^.*$ /maintence.php last;
}spa
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的強制跳轉設置.
---------------1、採用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 |
|
---------------2、採用nginx的497狀態碼---------------------
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 |
|
---------------3、利用meta的刷新做用將http跳轉到https---------------------
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 |
|
-----------------------------------------------------------------------------------------------------------------------------
下面是nginx反代tomcat,而且http強制跳轉至https。
訪問http://zrx.wangshibo.com和訪問http://172.29.34.33:8080/zrx/結果是同樣的
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 |
|
---------------4、經過proxy_redirec方式---------------------
1 2 3 |
|