Rewrite single page https to http Nginx Rewrite single page https to http Nginx nginx nginx

Rewrite single page https to http Nginx


I use it in the other direction (not tested in this direction but should work).

if ( $scheme = https ){  rewrite ^ http://$host$uri;}

EDIT: limit to a location and end don't try to rewrite more:

location / {  if ( $scheme = https )  {    rewrite ^ http://$host$uri last;  }}


I've used something similar to the following, which avoid's IfIsEvil and uses return instead of rewrite . However it fails DRY, which bothers me.. Suggestions welcome.

server {    listen 80;    server_name .example.com;    index index.html index.htm index.php;    location / {        try_files $uri $uri/ /index.php?$args;    }    location ~ \.php$ {        fastcgi_pass   unix:/var/run/php5-fpm.sock ;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include        fastcgi_params;    }}server {    listen              443 ssl;    server_name         .example.com;    ssl_certificate     /etc/ssl/certs/example.com.cert;    ssl_certificate_key /etc/ssl/private/example.com.key;    index index.html index.htm index.php;    # Rewrite only / to http    location = / {        return 301 http://$server_name$request_uri;    }    location / {        try_files $uri $uri/ /index.php?$args;    }    location ~ \.php$ {        fastcgi_pass   unix:/var/run/php5-fpm.sock ;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include        fastcgi_params;    }}

See also