域中的www在nginx中不工作

域中的www在nginx中不工作,nginx,named,no-www,Nginx,Named,No Www,我不熟悉使用nginx,嗯,不熟悉使用任何不是cpanel的东西。。。当您在url中包含www.时,我无法使用nginx让域正常工作 www.mydomain.com > not work 404 mydomain.com > works 我不确定是否在命名配置文件或nginx的服务器配置方面出错。我有点匆忙地学习,如果我在基本配置上犯了一些错误,我不会感到惊讶。我运行最新的nginx和php-fpm,除了我的域问题,它还能工作 我(试图?)运行子域,它们工作,但使用www.将导致

我不熟悉使用nginx,嗯,不熟悉使用任何不是cpanel的东西。。。当您在url中包含www.时,我无法使用nginx让域正常工作

www.mydomain.com > not work 404
mydomain.com > works
我不确定是否在命名配置文件或nginx的服务器配置方面出错。我有点匆忙地学习,如果我在基本配置上犯了一些错误,我不会感到惊讶。我运行最新的nginx和php-fpm,除了我的域问题,它还能工作

我(试图?)运行子域,它们工作,但使用www.将导致404。我使用main.org服务器域中的名称服务器等。 我将在下面发布所有相关信息,希望这里的人能够发现我正在犯/或犯的错误

etc/hosts 
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
184.xxx.xxx.146 server.servername.org servername.org 
named.conf

   ... 
   view "localhost_resolver" {
/* This view sets up named to be a localhost resolver ( caching only nameserver ).
 * If all you want is a caching-only nameserver, then you need only define this view:
 */
   # match-clients         { 127.0.0.0/24; };
   # match-destinations    { localhost; };
   match-clients      { any; };
   match-destinations { any; };
   recursion no;

        zone "servername.org" {
                type master;
                file "/var/named/servername.org.db";
        };

// optional - we act as the slave (secondary) for the delegated domain
zone "mydomain.com" IN {
  type slave;
  file "/var/named/mydomain.com.db";
  masters {10.10.0.24;};
}; 
allow-notify { 184.xxx.xxx.146; };
};
mydomain.com.db

$TTL    86400
mydomain.com.  IN      SOA     ns1.servername.org.      server.servername.org.        (
                                2002012013; Serial
                                1H      ; Refresh (change 1H to 6H in 3 days or so)
                                1800    ; Retry (change to 1H in 3 days)
                                2W      ; Expire
                                1D ); Minimum
mydomain.com.          IN      NS      ns1.servername.org.
mydomain.com.          IN      NS      ns2.servername.org.
ns1.servername.org.              IN      A       184.xxx.xxx.147
ns2.servername.org.             IN      A       184.xxx.xxx.148
mail.servername.org.             IN      A       184.xxx.xxx.146
mydomain.com.          IN      A       184.xxx.xxx.146
mydomain.com.          IN      MX      0       mail.servername.org.
@                               A       184.xxx.xxx.146
www                            A       184.xxx.xxx.146
nginx.conf使用include/etc/nginx/sites enabled/*; 以及nginx“mydomain.com”配置文件


我可以访问子域,所以我在这方面的可怕尝试似乎有点奏效,我被困在www.mydomain.com无法连接的原因上,而我会。随着我的进步,我正在阅读/学习更多,我不想做出改变,直到我理解了这些改变的作用。我可能会破坏更多的URL。

您正在nginx.conf的前几行重写www.domain.com。如果我没有错的话,重写和重定向是不同的事情。首先在服务器块上尝试此操作

server {
    server_name  www.mydomain.com;
    return       301 http://mydomain.com$request_uri;
}
改变

server_name mydomain.com www.mydomain.com


在第二个服务器块中。

我的解决方案对我有效

server {
    listen 80;
    server_name yourdomainname.com www.yourdomainname.com;
    return 301 https://$server_name$request_uri;
}
在该文件-->yourdomainname.conf中编写前面的代码


NginxThank:)从第二个服务器块中删除www对我来说是个好办法,顶部的重写可以让任何使用www的人都可以被发送到http//上,这一点现在也在起作用,尽管我发现我可以提高效率。谢谢你的帮助!有时,添加更多服务器名称指令可能需要增加
http{server\u names\u hash\u bucket\u size NN}
,其中NN是一个数字>=32
server_name mydomain.com
server {
    listen 80;
    server_name yourdomainname.com www.yourdomainname.com;
    return 301 https://$server_name$request_uri;
}