Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Tounea
V2EX  ›  Linux

请教一个 Nginx https 转 http 单个文件请求问题

  •  
  •   Tounea · Sep 18, 2022 · 2241 views
    This topic created in 1362 days ago, the information mentioned may be changed or developed.
    不知这个标题各位有没有看懂?我的意思是 nginx 启用全站 https ,但新的问题随之而来,像 POST 这类请求在 http 下就正常访问,在 https 下就不能正常访问,由于启用 https ,POST 访问请求 nginx 返回`301 Moved Permanently`,也有说设置 http 和 https 双方案,但这也不符合监管网络安全要求,由于这个是 PHP 写的 API 服务,需要 PHP-FPM 解析,所以我只想保留 http 能正常 POST 请求到 PHP 写的 API 服务就行,其他 page 仍然使用 https 访问。
    12 replies    2022-09-19 09:56:03 +08:00
    thinkershare
        1
    thinkershare  
       Sep 18, 2022
    不知道你在说啥, 同时监听 443 和 80 不就好了, 443 的时候走 HTTPS, 80 走 HTTP, 然后不要强制 HSTS 重定向.
    难道你是想要最多只允许 POST 可以走 HTTP, 其它类型不允许走 HTTP, 必须走 HTTPS?
    eason1874
        2
    eason1874  
       Sep 18, 2022
    不关 PHP 的事

    你这个应该是代码里的协议没有跟着实际访问协议改变,当访问 https 页面时,页面 post 代码还是提交到 http 就导致重定向
    V1Eerie
        3
    V1Eerie  
       Sep 19, 2022 via Android
    建议前端直接请求 https 的资源
    baobao1270
        4
    baobao1270  
       Sep 19, 2022
    “保留 http 能正常 POST 请求到 PHP 写的 API 服务” 如果 “http 和 https 双方案 不符合监管要求”的话,那么你这个方案也肯定不符合要求。POST 的数据走 HTTP 就是明文传输。

    既然是 POST ,那么大概率是 API 服务,建议在 API Client 里加入 302 跳转的判断
    yin1999
        5
    yin1999  
       Sep 19, 2022 via Android
    POST 请求是直接向 PHP 发起的?不能用 Nginx 做反向代理?
    Tounea
        6
    Tounea  
    OP
       Sep 19, 2022
    @yin1999 POST 访问 nginx ,nginx 反向代理 php-fpm
    sparkssssssss
        7
    sparkssssssss  
       Sep 19, 2022
    那就 http 处加条规则:
    ````
    set $jump 0;
    if ($request_method ~* POST) {
    set $jump "${jump}1";
    }

    if ($jump = "0") {
    return 301 https://$server_name$request_uri;
    }

    location / {
    proxy_pass xxxx;
    }
    ````
    sparkssssssss
        8
    sparkssssssss  
       Sep 19, 2022
    貌似 301 是没法带 postdata 的吧? 改成 return 307
    Judoon
        9
    Judoon  
       Sep 19, 2022
    301 和 302 换成 308,307
    salmon5
        10
    salmon5  
       Sep 19, 2022
    谁发起的 http 请求,改成 https 呗
    salmon5
        11
    salmon5  
       Sep 19, 2022
    改不了?发个邮件或者打个电话通知下呗
    julyclyde
        12
    julyclyde  
       Sep 19, 2022
    那你需要改客户端,建立以 SSL 为基准,拒不支持 plain 的技术体系

    301/302/307 别指望能够正常工作。这部分就是越改越乱的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1573 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 16:45 · PVG 00:45 · LAX 09:45 · JFK 12:45
    ♥ Do have faith in what you're doing.