force ssl for website

Discussion in 'Server Operation' started by joey3002, Mar 20, 2013.

  1. joey3002

    joey3002 New Member

    I am trying to force https for a site whenever someone goes to the http of the site.

    I am running nginx, I also have ispconfig 3.0.5.1

    I have tried:
    return 301 https://www.mysite.com$request_uri;

    however, that just goes into an endless loop

    Thanks
     
  2. almere

    almere Member HowtoForge Supporter

    Try this:

    Code:
    
    server {
           listen         *:80;
           server_name    yourdomain.com;
           rewrite        ^ https://$server_name$request_uri? permanent;
    }
    
    server {
    
            listen *:443 ssl;
            ssl_certificate /var/www/clients/clientnumber/webnumber/ssl/yourdomain.com.crt;
            ssl_certificate_key /var/www/clients/clientnumber/webnumber/ssl/yourdomain.com.key;
    
    ### the rest of your code
    }
    
     
  3. joey3002

    joey3002 New Member

    thanks that worked!!
     
  4. pharotek

    pharotek New Member

    Hi,

    The above method is almost how I'd like to achieve HTTPS over HTTP. According to NGINX, It's best practise for NGINX to use:
    Code:
    return 301 https://$host$request_uri;
    However, using this code or the above quoted method needs separate server blocks, correct? --Otherwise you will result with infinite loops.

    How does one achieve this with the sites within ISPConfig 3.0.5.3 using the directives field?

    Thank you.
     

Share This Page