大网数据广告活动
网站运营与故障问答

Browsers shows my website's IP instead of domain name in search results

· 52CE 我爱测

My website's IP address shows up when searching on google. Google knows the site exists, if I search for my website. Bing doesn't though, if I search for my website on bing. my nginx config file: server { listen 80; server_name _…

问题原文

原帖链接 · i'm a girl · CC BY-SA 4.0

My website's IP address shows up when searching on google. Google knows the site exists, if I search for my website. Bing doesn't though, if I search for my website on bing.

my nginx config file:

server {
  listen 80;
  server_name  _;
  return 301 https://$host$request_uri;
}


server {
  listen       443 ssl;
  server_name  localhost;

  ssl_certificate  /etc/letsencrypt/live/mosachi.ga/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/mosachi.ga/privkey.pem;

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

已采纳解答

原帖链接 · Thomas Ward · CC BY-SA 4.0

So, you have a case of an "NGINX Has Only One Site Configured" problem. That is, NGINX is serving the same data not just for your domain but for the bare IP address and any other request to your server/site (even with invalid domains - domains/subdomains which are NOT hosted on your site).

Thankfully, this is something you can fix.

FIRST we need to have a 'catch-all' to just drop non-valid domains and direct-to-IP requests. We'll redirect them all to your proper domain.

server {
    listen 80 default_server;

    server_name _;

    return 301 https://mosachi.ga$request_uri;
}

SECOND we need your config for your domain, but with a few tweaks (you shouldn't have server_name localhost; if you intend to serve an actual domain):

server {
  listen 80;
  server_name  mosachi.ga;
  return 301 https://mosachi.ga$request_uri;
}


server {
  listen       443 ssl;
  server_name  mosachi.ga;

  ssl_certificate  /etc/letsencrypt/live/mosachi.ga/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/mosachi.ga/privkey.pem;

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

Combined, your configuration should look like this:

# Catchall configuration - redir to the domain for bare and invalid domain requests
server {
    listen 80 default_server;

    server_name _;

    return 301 https://mosachi.ga$request_uri;
}

# HTTP handler to redirect to HTTPS for mosachi.ga
server {
  listen 80;
  server_name  mosachi.ga;
  return 301 https://mosachi.ga$request_uri;
}

# HTTPS for mosachi.ga
server {
  listen       443 ssl;
  server_name  mosachi.ga;

  ssl_certificate  /etc/letsencrypt/live/mosachi.ga/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/mosachi.ga/privkey.pem;

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

It may take some time for Google to play catchup here, but eventually the IP will just disappear from the search data, and the domain itself will show up in the search results instead.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。