如何防止谷歌索引我的 https 网址?

her*_*les 2 robots.txt nginx google-webmaster-tools

当我在 google 上搜索我的域时,它会显示我网站上的几个 https URL,因为 google 喜欢 https,但出于特殊原因,我不想索引 https/ssl 版本。

如何避免这种情况,全世界都只通过htaccess写解决方案,但大多数时候使用nginx!如何解决这个问题:

RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^robots.txt$ robots-deny-all.txt [L]
Run Code Online (Sandbox Code Playgroud)

机器人内容(在额外的机器人中):

User-agent: *
Disallow: /
Run Code Online (Sandbox Code Playgroud)

如何通过nginx重写规则做到这一点?

谢谢你。

只是一个附加(我的 /etc/nginx/sites-availble/somedomain.conf ):

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&$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";
}
Run Code Online (Sandbox Code Playgroud)

我的/etc/ngonx/nginx.conf

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;
#   }
#}
Run Code Online (Sandbox Code Playgroud)

bor*_*mke 5

在您的nginx.conf文件中,您可以向server侦听 443(SSL)的块添加标头:

server {
    listen 443 ssl;
    ...

    # This header will prevent search engines from indexing your https pages
    add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
}
Run Code Online (Sandbox Code Playgroud)