nginx redirige tous les http vers https avec une exception

Je voudrais redirect tout le trafic http vers https avec une exception. Quelque chose avec / preview / dans l’url je voudrais garder sur http.

J’ai essayé avec la configuration ci-dessous mais il continue de me dire que j’ai une boucle de redirection.

server { listen 80; server_name example.com; root /var/www/html/example.com/public; index index.php index.html; location /preview { try_files $uri $uri/ /index.php?$query_ssortingng; } location / { # we are in http server, but want https for normal # requests - redirect to https return 301 https://$server_name$request_uri; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 443; server_name example.com; ssl on; ssl_certificatee /etc/nginx/ssl/cert_chain.crt; ssl_certificatee_key /etc/nginx/ssl/server.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; add_header Ssortingct-Transport-Security max-age=31536000; access_log /var/log/nginx/example.com/access.log; error_log /var/log/nginx/example.com/error.log; charset utf-8; root /var/www/html/example.com/public; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_ssortingng; } location /preview { # we are in http server, but want https for normal # requests - redirect to https return 301 http://$server_name$request_uri; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

Pour être absolument certain de ne pas émettre de redirections dans /preview , vous pouvez toujours rendre la redirection conditionnelle, par exemple:

 listen 80; location / { if ($request_uri !~ /preview) { return 302 https://...; } }