DNS适用于www.,但不适用于http://



我有一台使用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地址。

这里可能有什么问题?

第一个服务器块中的服务器名称应该是:

server_name mycoolwebsite.com;

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

最新更新