【问题标题】:307 Temporary Redirect not work nginx 1.18307 临时重定向不起作用 nginx 1.18
【发布时间】:2022-07-06 11:38:32
【问题描述】:

我部署了 apirest 和其他服务需要它登录.... 前几天工作正常,因为我确实使用了 http,今天安装 https 并且所有请求 post/get 都可以使用 https 正常工作,但是我尝试调用相同的端点重定向不起作用。

我的目标是在使用 http://.... 或 https://...时调用透明方式...

我研究了这个案例,所有的人都在谈论 307/308 但对我不起作用

nginx - 站点启用/默认

server {
 listen 80;
 listen [::]:80;

 server_name mydomain.com;     
 return 307 https://$server_name$request_uri;
}

在这种情况下,我尝试使用 307 和 308 但不起作用 当我的请求使用 POST 时,我看到 access.log,nginx 使用方法 GET 重定向 url

  • 我的nginx版本是1.18
  • 我的域在 cloudflare 中注册....我怀疑这是否是问题
  • 重启服务并重启服务器....我也有同样的错误

请问有什么想法吗?

【问题讨论】:

    标签: nginx redirect https webserver cloudflare


    【解决方案1】:

    我可以解决这个问题....

    我在 cloudflare 中尝试了 diversitieds 配置...并且我检测到他们在始终使用 HTTPS 字段处于活动状态时修改了所有请求,在菜单 SSL/TLS > Edge 证书中

    Always Use HTTPS
    Redirect all requests with scheme “http” to “https”. This applies to all http requests to the zone.
    

    并且只取消了这个选项

    另外,我确认 return 308 在这个配置下可以正常工作:

    server {
      listen 80; ssl off;
      listen 443 ssl;
      listen [::]:443 ssl;
      include snippets/self-signed.conf;
      include snippets/ssl-params.conf;
    
      root /var/www/public;
    
      index index.php index.html index.htm index.nginx-debian.html;
    
      server_name api.mydomain.com;
    
      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt  { access_log off; log_not_found off; }
      location / {
        if ($scheme = "http") {            
            return 308 https://$server_name$request_uri;
        }
        autoindex on;
        try_files $uri $uri/ /index.php?$args;
      }
    .
    .
    .
    }
    

    #更新 05/07/2022 当我在其他服务器中激活 http/https 并且 domian 由 Cloudflare 管理时,我检测到其他相关问题

    我需要激活“DNS 管理”中的“代理”检查,因为我在使用 vb.net 的应用程序中遇到问题

    【讨论】:

      猜你喜欢
      • 2018-07-15
      • 2023-03-29
      • 2020-09-06
      • 2018-03-13
      • 2013-02-26
      • 2019-07-29
      • 2017-05-22
      • 2010-12-11
      • 1970-01-01
      相关资源
      最近更新 更多