繁体   English   中英

为什么Nginx将所有子域都重定向到非www,我只是将重定向www设置为非www

[英]Why nginx redirect all subdomain to non-www, I just setting redirect www to non-www

作业系统:Ubuntu 14.04 LTS

Nginx版本:1.6.0

我想将www重定向到非www,但是以下配置将ALL子域重定向到非www。

例如,我访问test.mydomain.com/index.php也会重定向到mydomain.com/index.php

访问ip_address / index.php还会重定向到mydomain.com/index.php,在FF 26和Chrome 34上进行测试,但IE11不会重定向。

http {
  gzip                on;
  include             mime.types;
  sendfile            on;
  default_type        application/octet-stream;
  keepalive_timeout   65;

  server {
    listen       80 default_server;
    server_name  mydomain.com;
    root         /var/www;

    location ~* \.php$ {
      fastcgi_index   index.php;
      fastcgi_pass    unix:/var/run/php-fpm.sock;
      include         fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }

    location / {
      index        index.html index.htm index.php;
    }

    error_page  404              /404.html;
    error_page  500 502 503 504  /50x.html;
  }

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

您的重定向在此子句中定义

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

删除行返回301 http://mydomain.com $ request_uri; 并且应该删除重定向。

如果这是服务器上的唯一站点,则可以删除整个服务器块,因为php处理的根目录和位置是在该服务器上面的server {}块中定义的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM