【问题标题】:How to redirect NGINX如何重定向 NGINX
【发布时间】:2022-01-10 05:16:13
【问题描述】:

我正在尝试从 https://support.example.com.br/ 为了 https://support.example.com.br/?SSO=1

我如何通过 nginx 做到这一点? 我的代码是这样的:

server {
    listen 8080;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location / {
        rewrite ^/$  /?SSO=1$1 redirect;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SERVER_NAME $host;    
    }
    location ~ /\.ht {
        deny  all;
    }
    location ~ php-errors\.log$ {
        deny all;
    }
}

【问题讨论】:

    标签: php nginx redirect mod-rewrite


    【解决方案1】:
    server {
      ...
    
      rewrite ^/$ /?SSO=1 permanent;
    }
    

    【讨论】:

      【解决方案2】:

      请不要就同一问题提出第二、第三等问题。使用 cmets 系统来澄清您对特定答案的问题。为了防止在请求中已指定 SSO 查询参数时重定向,请尝试以下操作:

      server {
          ... # global server block directives
      
          if ($arg_SSO = '') {
              rewrite ^/$ /?SSO=1 permanent;
          }
      
          ... # your locations goes here
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-25
        • 2022-01-11
        • 2012-05-04
        • 2018-09-21
        • 2015-05-09
        • 2020-10-29
        相关资源
        最近更新 更多