简体   繁体   English

为什么Nginx总是重定向到我的虚拟主机之一?

[英]Why nginx always redirects to one of my virtual hosts?

I have several virtual hosts configured with nginx. 我有几个用nginx配置的虚拟主机。 They are very simiral to each other and for most of them, everything seems to be working fine. 它们彼此非常相似,并且对于大多数它们来说,一切似乎都正常。

However, 然而,

  1. If I hit the server through a url that does not have any virtual host configured, nginx always redirects to one of the existing virtual hosts (seems to be the first one in the list. 如果我通过未配置任何虚拟主机的网址访问服务器,则nginx始终会重定向到现有的虚拟主机之一(似乎是列表中的第一个)。
  2. Same happens if I simply go there using IP address. 如果我只是使用IP地址去那里,也会发生同样的情况。

Most of the virtual hosts look like this: 大多数虚拟主机如下所示:

server {
        server_name  iibs.co;
        return 302 $scheme://www.iibs.co$request_uri;
}

server {
    server_name www.iibs.co;
    root /var/www/iibs.co;

    index index.php;

    include global/restrictions.conf;
    client_max_body_size 64M;

    # Additional rules go here.

    location / {
        # This is cool because no php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
    # Only include one of the files below.
#    include global/wordpress.conf;
#    include global/wordpress-ms-subdir.conf;
#    include global/wordpress-ms-subdomain.conf;
}

I just tried adding another one, very similar just with different domain and root. 我只是尝试添加另一个,非常相似,只是具有不同的域和根。 And that particular one, also getting redirected to the same first vhost on the list. 那个特定的,也被重定向到列表中的第一个虚拟主机。

At this point, I have no idea where and what should I looks for. 在这一点上,我不知道我应该在哪里寻找什么。

This is an example of default NGINX config for prevent redirects to the first of the existing virtual hosts . 这是默认NGINX配置的示例,用于防止重定向到现有的第一个虚拟主机。

### Block all illegal host headers. Taken from a discussion on nginx
### forums. Cf. http://forum.nginx.org/read.php?2,3482,3518 following
### a suggestion by Maxim Dounin. Also suggested in
### http://nginx.org/en/docs/http/request_processing.html#how_to_prevent_undefined_server_names.
server {
    listen 80 default_server; # IPv4
    #listen [::]:80 default_server ipv6only=on; # IPv6

    server_name _;
    server_name "";
    return 444;
}

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

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