【问题标题】:Configure unrouted domains in nginx to go to a special folder?在 nginx 中配置未路由的域以转到特殊文件夹?
【发布时间】:2015-11-22 08:00:56
【问题描述】:

我正在尝试将我的 nginx 配置为处理未路由的域,以便它们转到未路由域的特殊文件夹,而不是从我的主域文件夹加载未路由域。

一个例子:

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

    server {
        listen 80;
        server_name somedomain.com;
        root C:/web_root/somedomain.com;
        index index.html index.htm;
    }
    server {
        listen 80;
        server_name localhost;
        root C:/web_root/unrouted;
        index index.html index.htm;
    }
}

所以我希望所有尝试在我的服务器上设置 A 记录的访问者都转到特殊的未路由文件夹。

感谢您的帮助!

【问题讨论】:

    标签: nginx configuration


    【解决方案1】:

    默认服务器(即没有明确的server_name 匹配)是第一个具有匹配端口的server 容器。除非您通过在相应的 listen 指令上使用 default_server 关键字来指定默认服务器:

    listen 80 default_server;
    

    看看this document

    【讨论】:

    • 谢谢你,看来我只是误读了它并把servername 80 default_server; 留下了listen 80;
    猜你喜欢
    • 2017-05-30
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 2023-02-04
    • 1970-01-01
    • 2018-07-22
    相关资源
    最近更新 更多