contents directory

Discussion in 'Installation/Configuration' started by bobpit, Dec 23, 2013.

  1. bobpit

    bobpit Member

    I have an ubuntu 12.04 server with nginx and ispconfig3. I have installed an ssl too.

    The domain name is www.surf-anonymous.info

    My problem is that when I enter in the address bar www.surf-anonymous.info, then the browser takes me to the NGINX index.html file stored in the /usr/share/nginx/www directory. When I enter http://surf-anonymous.info/ or https://surf-anonymous.info/ then it takes me to the ISPConfig directory : /var/www/clients/client1/web2

    How can I make all 3 prefixes (www, http, https) point to the same place?
     
  2. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Go to the website settings in ISPConfig and set "auto subdomain" to "www".
     
  3. bobpit

    bobpit Member

    ok, this worked, they all go now to the ISPConfig directory : /var/www/clients/client1/web2.

    Now my problem is that I can see on the address 3 different versions of the domain name:
    www.surf-anonymous.info, http://surf-anonymous.info/, https://surf-anonymous.info/

    If it was Apache, then I could try to make the redirections through the .htaccess file. Now with NGinx what would you suggest me to do?
     
  4. bobpit

    bobpit Member

  5. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Add a htaccess to your surf-anonymous.info domain that redirects all http to https:
    Code:
     RewriteEngine On
     RewriteCond %{HTTPS} !=on
     RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
     
  6. bobpit

    bobpit Member

    I thought the htaccess works only for apache. I have NGINX. Are you sure it will work?
     
  7. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Oh dear, sorry. Overread that.
     
  8. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Maybe you can try something like this in the nginx vhost (didn't test!)
    Code:
     if ($ssl_protocol = "") {
           rewrite ^   https://$server_name$request_uri? permanent;
        }
     
  9. bobpit

    bobpit Member

    After making some other changes, now the redirections work like this:
    www.surf-anonymous.info -> https://surf-anonymous.info/
    http://surf-anonymous.info/ -> http://surf-anonymous.info/
    https://surf-anonymous.info/ -> https://surf-anonymous.info/

    So now I need to make the http -> https redirection.

    According to this (http://serverfault.com/questions/67...https-while-maintaining-sub-dom/171238#171238), the solution is this code:
    Code:
    server {
        listen         80;
        return 301 https://$host$request_uri;
    }
    I guess this goes to the vhost file. So I checked my /etc/nginx/sites-available/surf-anonymous.info.vhost file. Some of the contents appear to be writen by ispconfig3:
    Code:
    server {
            listen *:80;
    
            listen *:443 ssl;
            ssl_certificate /var/www/clients/client1/web2/ssl/www.surf-anonymous.info.crt;
            ssl_certificate_key /var/www/clients/client1/web2/ssl/www.surf-anonymous.info.key;
    
            server_name surf-anonymous.info www.surf-anonymous.info;
    
            root   /var/www/surf-anonymous.info/web;
    
            if ($http_host ~* "^(.+)\.surf-anonymous\.info$") {
                rewrite ^ $scheme://surf-anonymous.info$request_uri? permanent;
            }
    
            if ($http_host != "surf-anonymous.info") { rewrite ^(?!/\b(stats|error)\b)/(.*)$ https://surf-anonymous.info/$2 permanent; }
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    So it seems to me that I need to add this single line :
    Code:
    return 301 https://$host$request_uri;
    But where exactly do I place it?
     
  10. bobpit

    bobpit Member

    I changed the vhost file, so that the beginning is like this:

    Code:
    server {
      listen 80;
      server_name surf-anonymous.info www.surf-anonymous.info;
    
      return 301 https://surf-anonymous.info$request_uri;
    }
    
    server {
      listen 443 ssl;
      server_name surf-anonymous.info www.surf-anonymous.info;
    
      ssl_certificate /var/www/clients/client1/web2/ssl/www.surf-anonymous.info.crt;
      ssl_certificate_key /var/www/clients/client1/web2/ssl/www.surf-anonymous.info.key;
    
      root   /var/www/surf-anonymous.info/web;
    The solution works and now everything redirects to HTTPS.


    QUESTION:
    Shouldn't this be done from inside ISPConfig?
     

Share This Page