nGinx Proxy Pass:阻止显示根应用程序内容

问题描述

我是Nginx配置的新手,我尝试为imgproxy和ElasticSearch配置代理传递。

到目前为止,我已经实现了这一目标,并且代理通行证工作正常。

现在,我需要实现的是防止访问这些服务的根页面。

在一个示例中,当我尝试访问https://search.my-local-domain.local/时,会得到以下正常的输出,但不是我想要的输出:

{
    "name": "es","cluster_name": "docker-cluster","cluster_uuid": "YdhMfhYaS76nlxwYPOimQg","version": {
        "number": "7.5.2","build_flavor": "default","build_type": "docker","build_hash": "8bec50e1e0ad29dad5653712cf3bb580cd1afcdf","build_date": "2020-01-15T12:11:52.313576Z","build_snapshot": false,"lucene_version": "8.3.0","minimum_wire_compatibility_version": "6.8.0","minimum_index_compatibility_version": "6.0.0-beta1"
    },"tagline": "You Know,for Search"
}

与imgproxy相同。当我访问https://media.my-local-domain.local/时,将得到以下输出:

Hey,I'm imgproxy!
You can get me here: https://github.com/imgproxy/imgproxy

我的imgproxy Nginx配置如下:

server {
    # ... settings

    server_name media.my-local-domain.local;

    # ... settings

    location / {
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # imgproxy,is the Docker container name.
        proxy_pass http://imgproxy:8080;
    }
}

而Elasticsearch则是这样的:

server {
    # ... settings

    server_name search.my-local-domain.local;

    # ... settings

    location / {
        # Deny Nodes Shutdown API
        if ($request_filename ~ "_shutdown") {
            return 403;
            break;
        }

        # Deny access to Cluster API
        if ($request_filename ~ "_cluster") {
            return 403;
            break;
        }

        rewrite /(.*) /$1 break;

        # Pass requests to ElasticSearch
        proxy_pass http://es:9200;
        proxy_redirect off;
    }
}

因此,问题是,对于根URL,是否有可能(而不是默认输出)返回其他内容。甚至是空的HTML输出。

这可能吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)