nginx http 重定向 到https

前言

例如网站 用户之前一直使用http进行访问,现在要更换https,那么为了避免之前的用户还可以使用http进行访问,这个时候就可以利用nginx的重定向,将http 重定向到 htpps,这样用户访问旧的http,会重定向到https

具体直接上nginx配置

需要配置两个server

server {
    listen 80;
    
    #填写绑定证书的域名
    server_name xa-admin.net;
    
    #(第一种)把http的域名请求转成https
    #return 301 https://$host$request_uri;
    
    #(第二种)强制将http的URL重写成https
    rewrite ^(.*) https://$server_name$1 permanent; 
	}
	
	
	
	
	
	server {
		listen       443 ssl;
        server_name  xa-admin.net;
		ssl_certificate      /usr/local/nginx/ssl/admin/xa-admin.xa-equidle.pem;
        ssl_certificate_key  /usr/local/nginx/ssl/admin/xa-admin.xa-eqrt.net.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
	
	
	
		
		location / {
            root   html/xa-admin/;
            index  index.html index.htm;
        }
		
		location /api/ {
             proxy_pass   http://127.0.0.1:8892/;
			#proxy_set_header X-Forwarded-Proto https;
			 proxy_set_header Host $host;
			 proxy_set_header X-Real-IP $remote_addr;
			 proxy_set_header X-Forwarded-For $http_x_forwarded_for;
			 proxy_headers_hash_max_size 51200;
			 proxy_headers_hash_bucket_size 6400;
			 client_max_body_size 1024m;
			 
        }
	}

你可能感兴趣的:(nginx,https,nginx,http)