nginx使用scheme配置http重定向到https
相信现在很多朋友都已经在使用ssl证书来配置网站了,但由于http和https共存在一个配置文件里,很多人都想访问http的时候直接跳转到https,下面来看配置文件:
cat /etc/nginx/conf.d/www.slogra.com.conf
server {
listen 80;
listen 443 ssl;
server_name www.slogra.com;
root /data/www/;
index index.php index.htm index.html;
ssl on;
ssl_certificate www.slogra.com_bundle.crt;
ssl_certificate_key www.slogra.com.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+CHACHA20 EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
ssl_prefer_server_ciphers on;
location ~ \.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_ignore_client_abort on;
proxy_ignore_client_abort on;
fastcgi_index index.php;
include fastcgi.conf;
}
location ^~ /minipqiaqia/ {
proxy_pass http://127.0.0.1:8888/minipqiaqia/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /verification/ {
if ($scheme = "http") {
return 301 https://$server_name$request_uri;
}
proxy_pass http://127.0.0.1:8800/;
}
}可以看到我把verification这个目录做了http跳转到https上,有兴趣的朋友可以自己去研究.


评论: