m_createVoid 2020-07-16 16:54 采纳率: 50%
浏览 1050
已结题

Nginx将http转为https后的接口调用问题

内网环境的项目,要求用https,但是80端口和443端口都被禁用了。
项目开发用的是http,现在用Nginx将http转为https,前端已经能访问,可是调用后台接口就404了,请问各位大佬怎么解决这个问题?
ssl证书是用OpenSSL生成的。
环境是windows。

server {
        listen       9528 ssl;
        server_name  172.168.16.6;

        ssl_certificate C://Users//Desktop//ssl//server.crt;
        ssl_certificate_key C://Users//Desktop//ssl//server1.key;

        error_page 497 301 =307 https://172.168.16.6:9528$request_uri;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            try_files $uri $uri/ /index.html;
        }

    location /prod-api/{
        proxy_pass http://172.168.16.6:8201/;

        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        #proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Protocol $scheme;
    }
  • 写回答

3条回答 默认 最新

  • LQ的小蜜 2020-07-21 18:05
    关注

    首先你说的前端能请求,后端接口无法访问,没有具体介绍,不了解情况,接口跟端口不一会事,接口404跟nginx没关系。其次,80端口对应的http,ssl默认端口443对应的是https,最后,只要一开始你的nginx正常起来了,那你在地址重写rewrite一下,把默认的80http请求,重写成https对应的域名或者地址,就可以实现https请求了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料