【问题标题】:How to to forbid access my site from ip address+port using nginx?如何禁止使用 nginx 从 ip 地址+端口访问我的网站?
【发布时间】:2020-01-14 13:51:41
【问题描述】:

我有一个运行在 2333 端口上的 gunicorn 的 django 应用程序。我在 nginx.conf 中设置

server {
        listen 80;
        server_name mydomain.com;
        location / {
        proxy_cache my_cache;

        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:2333;
        expires 30d;
                }

现在我可以在地址 http://ipaddress:2333 和 mydomain.com 上查看我的 django 应用程序 但我不希望用户通过http://ipaddress:2333 查看我的网站。如何允许 nginx 仅使用 mydomain.com 访问我的网站。

我曾尝试使用“服务器默认值”。它不起作用。

server {
        listen 2333 default;
        server_name _;
        return 500;
}

【问题讨论】:

  • 你是怎么跑 gunicorn 的?

标签: django nginx gunicorn


【解决方案1】:

Nginx 与此无关。您的 Gunicorn (Django) 应用程序正在侦听端口 2333。因此,您可以通过连接到 http://$SERVER:2333 来绕过 nginx。即使你停止 nginx 也能正常工作。

您需要做的是告诉 gunicorn 仅在 localhost 上收听,例如与--bind=127.0.0.1:2333。然后端口 2333 将只接受来自本地网络接口的连接。

【讨论】:

  • 谢谢,我将 gunicorn 设置为在绑定 127.0.0.1:2333 上运行,并且成功了。
猜你喜欢
  • 2015-05-20
  • 2021-07-31
  • 2011-03-16
  • 1970-01-01
  • 2018-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多