【问题标题】:nginx - DNS works for www. but not for http://nginx - DNS 适用于 www。但不适用于 http://
【发布时间】:2016-11-02 14:08:37
【问题描述】:

我有一个使用 ngnix 的服务器,我有一个配置文件:

server {
   listen 80;
   server_name http://mycoolwebsite.com/;
   return 301 http://www.mycoolwebsite.com$request_uri;
}

server {
    listen 80;

    root /var/www/website/front/public;
    index index.php index.html index.htm;

    server_name  www.mycoolwebsite.com;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

现在当我输入http://www.mycoolwebsite.com 时,网站显示正常。每当我输入http://mycoolwebsite.com 时,我都会得到:

无法访问此站点 |找不到服务器 DNS 地址。

这可能是什么问题?

【问题讨论】:

    标签: nginx dns


    【解决方案1】:

    您在第一个服务器块中的服务器名称应为:

    server_name mycoolwebsite.com;
    

    另外,确保mycoolwebsite.com 的 DNS 条目指向您的服务器 IP。这可能与www.mycoolwebsite.com 的条目分开。

    【讨论】:

    • 从第一个服务器块中删除了 http:// 并且仍然收到错误:(
    • 确保也删除尾随的/。要诊断 DNS 问题,请运行 dig mycoolwebsite.comdig www.mycoolwebsite.com 并查看两个 IP 是否指向同一服务器。
    • 谢谢!所以我做了dig 并且 (www.mycoolwebsite.com) 提供了一个 IP 地址,而 (mycoolwebsite.com) 提供了没有 IP 地址的 ns1.digitalocean.com?
    • 您需要配置 DNS 服务器(可能在 DigitalOcean 上运行)以返回 mycoolwebsite.com 的正确 IP。如果是 DigitalOcean,这可能会有所帮助:digitalocean.com/community/tutorials/…
    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    相关资源
    最近更新 更多