Nginx 如何防止谷歌索引我的https URL?
当我在谷歌上搜索我的域名时,它会显示我网站上的几个https URL,因为谷歌喜欢https,但出于特殊原因,我不想索引https/ssl版本 如何避免这种情况,全世界都只通过htaccess编写解决方案,但当大多数人使用nginx时!如何解决这个问题:Nginx 如何防止谷歌索引我的https URL?,nginx,robots.txt,google-webmaster-tools,Nginx,Robots.txt,Google Webmaster Tools,当我在谷歌上搜索我的域名时,它会显示我网站上的几个https URL,因为谷歌喜欢https,但出于特殊原因,我不想索引https/ssl版本 如何避免这种情况,全世界都只通过htaccess编写解决方案,但当大多数人使用nginx时!如何解决这个问题: RewriteEngine On RewriteCond %{HTTPS} =on RewriteRule ^robots.txt$ robots-deny-all.txt [L] 机器人内容(在额外机器人中): 如何通过nginx重写规则做
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^robots.txt$ robots-deny-all.txt [L]
机器人内容(在额外机器人中):
如何通过nginx重写规则做到这一点
多谢各位
只是一个加数(my/etc/nginx/sites available/somedomain.conf):
my/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;
# }
#}
在nginx.conf文件中,您可以向侦听443(SSL)的服务器块添加头:
要执行类似于.htaccess
文件的操作,请使用:
location = /robots.txt {
if ($scheme = https) {
rewrite ^ /robots-deny-all.txt permanent;
}
}
请参阅if
的使用,非常感谢您的回复@borislemke抱歉,我在它准备好之前意外发送了它,在5分钟限制之前没有更好的时间。我在问题中添加了我的服务器块,您能告诉我是否仍然需要添加linsten 443 ssl;在服务器块的开头,因为最后我已经默认拥有了它。。。。我在哪里添加add_头…?我很困惑,首先你在我的nginx.conf中说,然后我在服务器块中添加,我很困惑,使用我的设置说add-on add_头X-Rob。。。(在nginx.conf文件中不存在服务器块。但存在于每个vhost中…在nginx站点中可用/somedomain.conf)再次感谢。当我说nginx.conf
时,它不一定是那个特定的文件。我只是想说在你的nginx配置中。无论你把它放在哪里。如果您使用启用的站点
,那么它就是ishi@borislemke。。我已经在我的/etc/nginx/sites available/somedomain.conf中添加了,请参见我的提问,并告诉我是否放置了正确的位置。(我在文件末尾放了)…你的设置可以阻止谷歌蜘蛛抓取我的HTTP URL吗?危害我的HTTP URL的索引?正确的解决方案。非常感谢您的回复@Richard Smith这个问题真的让我睡不着觉,当人们访问我的ssl URL时会很可怕,正如您在我的区块中看到的,我添加了您的配置(请告诉我是否添加了正确的位置),但我仍在测试,我不知道如何在google中获取我的URL SSL索引,知道使用这个新配置,它是否真的会跳过我的https URL,我只使用它通过https访问我的登录页面,其他什么都没有。我不能标记为有用,因为我的分数不到15分,但当我测试时,从google缓存中删除我的URL,如果我的https URL不再被索引,只有我的http被索引,我肯定会标记为您的答案解决了,因为这个问题是我所遇到过的最严重的问题之一。
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;
# }
#}
server {
listen 443 ssl;
...
# This header will prevent search engines from indexing your https pages
add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
}
location = /robots.txt {
if ($scheme = https) {
rewrite ^ /robots-deny-all.txt permanent;
}
}