如何通过https访问部署在服务器上的api?
发布于 6 年前 作者 LynanBreeze 3082 次浏览 来自 问答

这两天我把nginx设置了https 之前的api访问地址是http://ip:3000/api/… 现在使用http://ip:3000/api/article/news仍然可以访问,但是使用https无法访问 我尝试在nginx配置文件中添加 server { listen 3000 ssl; server_name localhost:3000;

ssl_certificate cert/my.pem; ssl_certificate_key cert/my.key;

ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; }

重启nginx仍然无法访问,请教大家!

2 回复

反向代理,可以参考下我的:

location /api/imgs {
        rewrite /api/imgs(.*) / break;
        proxy_pass http://localhost:3000;
        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;
    }

@blackmatch 谢谢!成功解决我的问题!

回到顶部