美文网首页
nginx 代理https到http重定向失败的问题

nginx 代理https到http重定向失败的问题

作者: 田文健 | 来源:发表于2019-04-26 15:49 被阅读0次

nginx 可以代理https到http,外网用https,内网使用http,这样的反向代理模式,安全简单。
但是存在一个问题,如果服务存在重定向的行为,那么会重定向到http产生错误,这是时候需要配置Nginx:

server{
 listen 443;
 server_name xx.xx.com;
 ssl on;
 ssl_certificate /root/key/server.crt;
 ssl_certificate_key /root/key/server.key;
 location / {
        proxy_pass http://127.0.0.1:8086;
        proxy_redirect off;
        proxy_set_header   Host    $host;
        proxy_set_header   X-Real-IP   $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
 }
}

#http to https
server {
    listen 80;
    server_name xx.xx.com;
 
    return 301 https://$server_name$request_uri;
  
    location ~ / {
       root /var/www/html/8080;
       index index.html index.php index.htm;
    }
}
 

这样Nginx 把http重定向为https就行了

相关文章

网友评论

      本文标题:nginx 代理https到http重定向失败的问题

      本文链接:https://www.haomeiwen.com/subject/vpcqnqtx.html