Nginx忽略我的第二个服务器指令

我在ubuntu 14.04上通过apt-get install nginx 。 因此,默认设置包括目录/etc/nginx/conf.d/configuration

 include /etc/nginx/conf.d/*.conf; 

在我的conf.d文件夹中,我有以下两个文件(site1.conf和site2.conf)

 server { listen 80; location /site1/ { proxy_pass http://127.0.0.1:3000/; } } 

 server { listen 80; location /site2/ { proxy_pass http://127.0.0.1:3001/; } } 

当我访问http://xxxx/site1/ ,如预期的那样,我从端口3000上运行服务器得到响应。 当我访问http://xxxx/site2/ ,但是,我得到了404。在错误日志中,它说

 2014/07/29 09:37:51 [error] 23060#0: *9 "/usr/share/nginx/html/site2/index.html" is not found (2: No such file or directory), client: 5.57.55.92, server: , request: "GET /site2/ HTTP/1.1", host: "217.147.85.96" 

这表明它使用默认的configuration,考虑到site2是一个文件夹,在其中find一个index.html文件。

这是为什么? 我找不到为什么会这样。 我尝试设置两个configurationserver_name,但没有什么区别。

两个location指令都需要处于相同的虚拟主机configuration中。

不同的虚拟主机是为了允许不同的主机名称和/或协议由同一个服务器提供服务。 你有效地做了什么是创build两个虚拟主机,但没有办法区分两者,例如与server_name指令。 由于nginx不能区分它们,因此nginx只是使用第一个默认的vhostconfiguration,并试图映射请求,但由于既没有一个名为site2的目录,也没有一个location指令,所以它不能提供这个服务。