Join the community today
Become a Member

Nginx Redirect HTTPS to HTTP

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by nehafarzana, Sep 29, 2014.

  1. nehafarzana

    nehafarzana New Member

    12
    1
    3
    Jul 24, 2014
    Ratings:
    +1
    Local Time:
    11:20 PM
    1.7.3
    5.5.38
    Hello,
    I am trying to disable HTTPs and redirect HTTPs to HTTP. What will be the best nginx conf to do it?
     
  2. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    3:50 AM
    Nginx 1.13.x
    MariaDB 5.5
    Just remove the redirect and notify all visitors to clear their browser caches and restart their browsers as the 301 permanent redirect is cached permanently in the visitors browsers, so will result in an error if visitors visit the page. If you attempt a nginx rewrite redirect from https back to http, you will end up in a redirect loop and visitor browser cache will redirect http back to https.
    Code:
    #server {
    #server_name domain.com www.domain.com;
    #return 301 https://$server_name$request_uri;
    #}
    
    usually once you go https you should keep using https and not go back to http non-SSL.
     
  3. nehafarzana

    nehafarzana New Member

    12
    1
    3
    Jul 24, 2014
    Ratings:
    +1
    Local Time:
    11:20 PM
    1.7.3
    5.5.38
    Thanks George, that is why I have been getting lot of redirect loops and I thought I might be doing something wrong.

    However, is it possible to exclude a page from https? Some embeded iframe codes don't work when the codes are http and placed on https. So, I wanted to remove https from my site. But, it will be really hard work to let everyone know about the change and to ask them clear cache and cookies.
     
  4. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    3:50 AM
    Nginx 1.13.x
    MariaDB 5.5
    what is the iframe code for ? If iframe supports https just use that or use //domain.com instead of http://domain.com
     
  5. nehafarzana

    nehafarzana New Member

    12
    1
    3
    Jul 24, 2014
    Ratings:
    +1
    Local Time:
    11:20 PM
    1.7.3
    5.5.38
    For live score. However, //domain.com didn't work for me. Well, there is another issue arised. I have created a subdomain which is linked to my main domain and not HTTPs. But, when visitors are trying to go to subdomain they are getting HTTPs error (somehow the browser is redirecting them to HTTPs instead of HTTP.
     
  6. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    3:50 AM
    Nginx 1.13.x
    MariaDB 5.5
    subdomain site should have a separate nginx vhost which would prevent such redirects if the subdomain is non-https setup and configured
     
  7. nehafarzana

    nehafarzana New Member

    12
    1
    3
    Jul 24, 2014
    Ratings:
    +1
    Local Time:
    11:20 PM
    1.7.3
    5.5.38
    Subdomain is hosted on another server and has different nginx vhost. Can it be the reason? Should both be in same server?
     
  8. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    3:50 AM
    Nginx 1.13.x
    MariaDB 5.5
    can't be the reason, if the maindomain.com and subdomain.maindomain.com have separate nginx vhosts on same or different server, it shouldn't matter and shouldn't redirect subdomain to https if you have configured nginx vhost correctly..

    post the contents for both nginx vhost here
     
  9. nehafarzana

    nehafarzana New Member

    12
    1
    3
    Jul 24, 2014
    Ratings:
    +1
    Local Time:
    11:20 PM
    1.7.3
    5.5.38
  10. eva2000

    eva2000 Administrator Staff Member

    31,001
    6,920
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,426
    Local Time:
    3:50 AM
    Nginx 1.13.x
    MariaDB 5.5
    for subdomain no need to redirect 301 at all if you only serve http

    remove that line
    Code:
    return 301 $scheme://Sub.MyDomain.com$request_uri;