简体   繁体   English

除www.website.com以外的所有配置?

[英]Catch-all configuration except for www.website.com?

Using Nginx, I'm trying to configure my server to accept all domains that point to the IP of my server, by showing them a specific website, but when accessing the www.example.com (main website), I'd show an other content. 通过使用Nginx,我试图通过显示特定的网站来配置服务器以使其接受指向服务器IP的所有域,但是在访问www.example.com(主网站)时,我会显示一个其他内容。

Here's what I did so far: 这是我到目前为止所做的:

server {
    // Redirect www to non-www
    listen       80;
    server_name  www.example.com;
    return       301 $scheme://example.com$request_uri;
}

server {
    listen       80;
    server_name  example.com;
    // rest of the configuration
}

server {
    // Catch all
    listen       80 default_server;

    // I also tried 

    // server_name _;

    // Without any luck.

    // Rest of the configuration
}

The problem with this configuration is that every request made to this server not being www.example.com or example.com is took under example.com server configuration, not the catch all. 此配置的问题在于,对该服务器(不是www.example.com或example.com)的每个请求均采用example.com服务器配置,而不是全部捕获。

I'd like to cath only www.example.com/example.com in the first two configurations, and all the others in the last configuration. 我只想在前两个配置中添加www.example.com/example.com,并在最后一个配置中添加所有其他内容。

I suggest putting your server on top of the file :) 我建议将您的服务器放在文件之上:)

I think nginx wants default servers to be on top of -a- file. 我认为nginx希望默认服务器位于-a-文件之上。 I have really much files on my server, but there is one with a default server as first server declaration, and that works. 我的服务器上确实有很多文件,但是有一个默认服务器作为第一个服务器声明的文件,并且可以正常工作。

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

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