Welcome to Centmin Mod Community
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:
    7:35 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

    54,113
    12,179
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,739
    Local Time:
    12:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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:
    7:35 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

    54,113
    12,179
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,739
    Local Time:
    12:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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:
    7:35 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

    54,113
    12,179
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,739
    Local Time:
    12:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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:
    7:35 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

    54,113
    12,179
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,739
    Local Time:
    12:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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:
    7:35 PM
    1.7.3
    5.5.38
  10. eva2000

    eva2000 Administrator Staff Member

    54,113
    12,179
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,739
    Local Time:
    12:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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;
     
  11. Kintaro

    Kintaro Member

    106
    11
    18
    Dec 2, 2016
    Italy
    Ratings:
    +30
    Local Time:
    3:05 PM
    1.15.x
    MariaDB 10
    and in case I need to disable only a couple of pages (I need to iframe some http content in it)?

    plus I need to re-issue a http+https with acmetools, right?
    (right now I have a https default)
     
    Last edited: Nov 14, 2018