小编Del*_*Del的帖子

使用 Nginx 阻止未发送至我的域的连接

我正在 AWS elastic beanstalk 上运行 django 应用程序,并且收到尝试扫描漏洞的机器人发送的垃圾邮件。它会导致大量错误,例如:

(其中 xx.xxx.xx.xx 是我的 ec2 实例的 IP 地址。)

DisallowedHost at //www/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
Invalid HTTP_HOST header: 'xx.xxx.xx.xx'. You may need to add 'xx.xxx.xxx.xx' to ALLOWED_HOSTS.
Run Code Online (Sandbox Code Playgroud)

我的合法用户只能使用域名访问该网站。我一直在尝试找出如何修改我的 nginx 配置以阻止所有未寻址到 *.mydomain.com 或 mydomain.com 的连接。

我根据需要动态添加和删除子域,因此我为子域使用通配符。

AWS Elastic beanstalk 为我生成以下默认配置文件:

/etc/nginx/nginx.conf

#Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    32788;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" …
Run Code Online (Sandbox Code Playgroud)

nginx django elastic-beanstalk

6
推荐指数
1
解决办法
6985
查看次数

标签 统计

django ×1

elastic-beanstalk ×1

nginx ×1