【问题标题】:nginx not working with gunicorn for external IP'snginx 不能与 gunicorn 一起使用外部 IP
【发布时间】:2015-04-23 16:06:18
【问题描述】:

我在 AWS 上将 nginx 和 gunicorn 用于 django 应用程序。 这是我的 /etc/nginx/sites-enabled/mywebsite

server {
    listen 80;
    server_name mywebsite.com;
    location / {
        proxy_pass http://127.0.0.1:8001;
    }

    location /static/ {
        autoindex on;
        alias /home/ubuntu/mywebsite/staticfiles/;
    }
}

我正在运行的 Gunicorn 命令。

gunicorn mywebsite.wsgi:application --bind=127.0.0.1:8001

这一切都在 AWS 上

问题是我可以通过访问 mywebsite.com 访问该网站,它可以在我家庭网络上的任何机器上按预期工作,但其他人(不在我家庭网络上)仍然欢迎使用 nginx。

我的域 mywebsite.com 指向我的弹性 IP 我还在 AWS 上打开了 80 端口。

【问题讨论】:

  • 嗯。也许他们访问 www.mywebsite.com ?尝试其他网络,如果有任何问题,请告诉我
  • 对不起,我对此很陌生。因此,mywebsite.com 和 www.mywebsite.com 的服务器名称将不同。有没有办法同时添加它们。
  • 这样写server_name mywebsite.com www.mywebsite.com;

标签: django amazon-web-services nginx gunicorn


【解决方案1】:

您网络之外的其他人很有可能访问 www.mywebsite.com。把server_name改成。

server {
    listen 80;
    server_name mywebsite.com www.mywebsite.com;
    location / {
        proxy_pass http://127.0.0.1:8001;
    }

    location /static/ {
        autoindex on;
        alias /home/ubuntu/mywebsite/staticfiles/;
    }
}

【讨论】:

  • 非常感谢.....现在可以工作了。我在这上面浪费了很多时间。我非常感谢您的帮助
  • 也可以添加:server_name mywebsite.com *.mywebsite.com;允许来自 www.mywebsite.com 和anything.mywebsite.com 的流量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-12
  • 2019-09-08
  • 1970-01-01
  • 2021-02-26
  • 1970-01-01
  • 2020-08-15
  • 2017-08-20
相关资源
最近更新 更多