title: How to prevent google indexing my https urls?
body: <p>When I search for my domain on google, it displays several https URLs from my website, because google loves https, but for particular reasons I do not want to index https / ssl versions.</p>
  
  <p>How to avoid this, the whole world only writes solution via htaccess, but when most use nginx! How to solve this:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTPS} =on
  RewriteRule ^robots.txt$ robots-deny-all.txt [L]
  </code></pre>
  
  <p>robot content (in the extra robots):    </p>
  
  <pre><code>User-agent: *
  Disallow: /
  </code></pre>
  
  <p>How to do this via nginx rewrite rules?</p>
  
  <p>Thank you.</p>
  
  <p><strong>JUST an addend</strong> ( my /etc/nginx/sites-availble/somedomain.conf ):</p>
  
  <pre><code>server {
      server_name somedomain.com www.somedomain.com;
      listen 100.10.10.10;
      root /home/somedomain/public_html;
      index index.php index.html index.htm;
      access_log /var/log/virtualmin/somedomain.com_access_log;
      error_log /var/log/virtualmin/somedomain.com_error_log;
      fastcgi_param GATEWAY_INTERFACE CGI/1.1;
      fastcgi_param SERVER_SOFTWARE nginx;
      fastcgi_param QUERY_STRING $query_string;
      fastcgi_param REQUEST_METHOD $request_method;
      fastcgi_param CONTENT_TYPE $content_type;
      fastcgi_param CONTENT_LENGTH $content_length;
      fastcgi_param SCRIPT_FILENAME /home/somedomain/public_html$fastcgi_script_name;
      fastcgi_param SCRIPT_NAME $fastcgi_script_name;
      fastcgi_param REQUEST_URI $request_uri;
      fastcgi_param DOCUMENT_URI $document_uri;
      fastcgi_param DOCUMENT_ROOT /home/somedomain/public_html;
      fastcgi_param SERVER_PROTOCOL $server_protocol;
      fastcgi_param REMOTE_ADDR $remote_addr;
      fastcgi_param REMOTE_PORT $remote_port;
      fastcgi_param SERVER_ADDR $server_addr;
      fastcgi_param SERVER_PORT $server_port;
      fastcgi_param SERVER_NAME $server_name;
      fastcgi_param HTTPS $https;
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
      }
          ##
          #  cache client
          ##
   location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
           access_log        off;
           log_not_found     off;
           expires           30d;
       }
   location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  try_files $uri $uri/ /index.php?q=$uri&amp;$args;
  # Uncomment to enable naxsi on this location
  # include /etc/nginx/naxsi.rules
  }
  location = /robots.txt {
      if ($scheme = https) {
          rewrite ^ /robots-deny-all.txt permanent;
      }
  }
  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
  root /usr/share/nginx/html;
  }
      listen 100.10.10.10:443 ssl;
      ssl_certificate /home/somedomain/ssl.cert;
      ssl_certificate_key /home/somedomain/ssl.key;
      add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
  }
  </code></pre>
  
  <p>my /etc/ngonx/nginx.conf</p>
  
  <pre><code>user www-data;
  worker_processes auto;
  pid /run/nginx.pid;
  
  events {
      worker_connections 1024;
      # multi_accept on;
  }
  
  http {
  
      ##
      # Basic Settings
      ##
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      # server_tokens off;
  
      # server_names_hash_bucket_size 64;
      # server_name_in_redirect off;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      ##
      # SSL Settings
      ##
  
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
      ssl_prefer_server_ciphers on;
  
      ##
      # Logging Settings
      ##
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      ##
      # Gzip Settings
      ##
  
      gzip on;
      gzip_disable "msie6";
  
      gzip_vary on;
      gzip_proxied any;
      gzip_comp_level 6;
      gzip_buffers 16 8k;
      gzip_http_version 1.1;
      gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  
      ##
      # Virtual Host Configs
      ##
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
      server_names_hash_bucket_size 128;
  client_max_body_size 100M;
  client_body_buffer_size 16k;
  
  fastcgi_buffers 8 16k;
  fastcgi_buffer_size 32k;
  fastcgi_connect_timeout 180;
  fastcgi_send_timeout 180;
  fastcgi_read_timeout 180;
  }
  
  
  #mail {
  #   # See sample authentication script at:
  #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  # 
  #   # auth_http localhost/auth.php;
  #   # pop3_capabilities "TOP" "USER";
  #   # imap_capabilities "IMAP4rev1" "UIDPLUS";
  # 
  #   server {
  #       listen     localhost:110;
  #       protocol   pop3;
  #       proxy      on;
  #   }
  # 
  #   server {
  #       listen     localhost:143;
  #       protocol   imap;
  #       proxy      on;
  #   }
  #}
  </code></pre>