camry 2015-9-10 15:20
在 CentOS 6下設定 Nginx Reverse Proxy 代理 HTTPS (SSL) 的方法
要知道如何申請及安裝 SSL憑證可以參考這篇教學:
[url=http://dz.adj.idv.tw/thread-159047-1-1.html]Nginx 如何安裝 Namecheap Comodo PositiveSSL 憑證[/url]
觀念: 讓 Client 端和 proxy 之間使用SSL加密協定, 再將 request 請求給未加密的Web伺服器.
底下的設定是加在 Reverse Proxy 的主機上~
[quote]
#----------------------------------------------------
# adj.com.tw
#----------------------------------------------------
server {
listen 443;
server_name [color=Red]adj.com.tw www.adj.com.tw[/color];
access_log /var/log/nginx/show/adj.com.tw.access.log;
error_log /var/log/nginx/show/adj.com.tw.error.log;
ssl on;
ssl_certificate [color=Red]/etc/nginx/certs/adj/ssl-bundle.crt[/color];
ssl_certificate_key [color=Red]/etc/nginx/certs/adj/server.key[/color];
if ( $host = 'adj.com.tw' ) {
rewrite ^/(.*)$ https://www.adj.com.tw[url=https://www.taiwanteama.com.tw/]/[/url]$1 permanent;
}
location / {
proxy_pass [color=Red]https://11.22.33.44[/color];
proxy_buffering on;
proxy_cache cache_one;
proxy_cache_valid 200 304 7d;
proxy_cache_valid 301 302 10m;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
add_header X-Via $server_addr;
add_header X-Cache-status $upstream_cache_status;
expires 7d;
### force timeouts if one of backend is died ##
proxy_next_upstream http_502 http_504 error timeout invalid_header;
### Set headers ####
proxy_set_header Host [color=Red]www.adj.com.tw[/color];
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
### Most PHP, Python, Rails, Java App can use this header ###
proxy_set_header X-Forwarded-Proto https;
}
}
[/quote]
照這樣的設定...將 adj.com.tw 改成自己的網址就可以了~~