如何阻止Nginxredirect到默认服务器?

我正在用PHP 5.3为多个运行wordpress的网站设置Nginx。 我刚刚添加了一个新的网站,它被redirect到默认的欢迎页面。 我在日志中看不到任何“真正的”错误。

这里是我的缩写nginx.conf:

http { access_log /var/log/nginx_access.log; index index.php index.html; server { listen 80 default_server; server_name _; root /opt/nginx/html; location / { } } server { listen 80; server_name example.com *.example.com; rewrite ^ $scheme://www.example.com$request_uri? permanent; } server { listen 80; server_name www.example.com; root /home/example/example.com; location / { } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm/example.sock; fastcgi_index index.php; include fastcgi_params; } } 

正如注释所指出的,服务器块中的listen指令将其定义为默认值(来源: http : //nginx.org/en/docs/http/request_processing.html ):

 listen 80 default_server; 

下面的声明意味着一个无效的服务器名称(来源: http : //nginx.org/en/docs/http/server_names.html )(所以它不会与任何有效的域相交):

 Server_name _; 

要解决你的问题,确保你有一个服务器端口监听(端口)和server_name(虚拟主机) – 这将首先触发,当你从“更精确到不太精确”,当你做虚拟主机名称匹配在Nginx :

 Listen 80; Server_name your-domain-name.com;