Automatic trailing slash redirect and scheme

Igor A. Ippolitov iippolitov at nginx.com
Thu Aug 22 15:08:24 UTC 2019


Hello,

You can try adding an 'error_page 301 @returnme' and then a location 
like this:
location @returnme {
     return 301 https://$host$uri/$is_args$args;
}

Regards,
Igor

On 22.08.2019 16:22, Jean-Daniel FISCHER wrote:
> Hi,
>
> I an trying to set the sheme used in automatic redirect generates by 
> nginx when trailing slash is missing. The nginx server is behind a 
> proxy that handles ssl, hence all requests are made using http so 
> nginx use http in absolute redirect.
>
> Is there a way to configure nginx to use the value of 
> "$http_x_forwarded_proto" ?
>
> The server conf:
> server {
>      listen  8080;
>      server_name _;
>      gzip on;
>      gzip_disable "msie6";
>      root /usr/share/nginx/www;
>      # Prevent redirect to have port 8080
>      port_in_redirect off;
>
>      # 404
>      error_page 404 /404.html;
>
>      # Redir auto to http
>      if ($http_x_forwarded_proto = http) {
>          return 301 https://$host$request_uri;
>      }
>
>      # Ensure remote ip is the right one
>      set_real_ip_from0.0.0.0/0  <http://0.0.0.0/0>;
>      real_ip_header    X-Forwarded-For;
>      real_ip_recursive on;
>
>      # Cache control on image
>      location ~ ^/fr/(.*\.(bmp|gif|jpeg|jpg|jxr|hdp|wdp|png|svg|svgz|tif|tiff|wbmp|webp|jng|cur|ico|woff|woff2))$ {
>          add_header Cache-Control public,max-age=86400;
>          alias /usr/share/nginx/www/$1;
>      }
>
>      # Serving data configuration
>      location ~ ^/fr/(.*) {
>          include /etc/nginx/redirect/*;
>          alias /usr/share/nginx/www/$1;
>      }
> }
> Regards,
>
> -- 
>
> <https://cedreo.com/> 	
> 	*Jean-Daniel Fischer*
> Developer
>
> +33 (0)2 40 18 04 77
> 16 Bd Charles de Gaulle, Bât. B
> 44800 Saint-Herblain, France
>
> LinkedIn <https://linkedin.com/company/cedreo/> 	Facebook 
> <https://facebook.com/cedreo3d/> 	YouTube 
> <https://youtube.com/channel/UCj1QYnZvV8Wbtdivc4GD7CA> 	Instagram 
> <https://instagram.com/cedreo3D/>
>
> *
> Cedreo est noté* Trustpilot Stars 
> <https://fr.trustpilot.com/review/www.cedreo.com?utm_medium=Trustbox&utm_source=EmailSignature1> 
> sur Trustpilot Logo 
> <https://fr.trustpilot.com/review/www.cedreo.com?utm_medium=Trustbox&utm_source=EmailSignature1>
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190822/3774f78e/attachment.html>


More information about the nginx mailing list