【问题标题】:Django server not opening with 0.0.0.0:8000Django 服务器未以 0.0.0.0:8000 打开
【发布时间】:2021-09-21 07:30:20
【问题描述】:

我有一个在 Nginx 上运行的 AWS 服务器,它托管了一个在服务器上运行良好的 React 应用程序。 现在我希望在同一台服务器上可以使用用于 restframework 的 Django 应用程序。

我关注Document 并在服务器上上传了Django 应用程序,并尝试通过尝试python3 manage.py runserver 0.0.0.0:8000 来运行该应用程序。没有错误,但我无法使用http://server_domain_or_IP:8000 访问我的 ip。

/etc/nginx/conf.d/example.org.conf 中的 Nginx 配置

server {
        listen 80 default_server;
        server_name example.org;
        return 301 https://example.org;
}

server {
        listen 443 ssl;
        server_name example.org;

        ssl_certificate /etc/nginx/ssl/ssl_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/example.key;

        location / {
                root /home/ubuntu/example/build;
                index index.html index.htm;
        }
}

请帮忙看看我哪里出错了?

【问题讨论】:

  • 显示你的 nginx 设置。
  • 嗨@RanuVijay,添加了Nginx配置
  • 希望example.org是一个占位符,而不是实际的域名,否则,很明显是它没有指向你注册的域的问题。还有防火墙、关闭的端口、DNS 设置等等等等……
  • 是的 example.org 仅用于演示目的。我对我的实时域进行了配置

标签: django nginx


【解决方案1】:

因此,您的 Django 在 localhost:8000 上运行,并且在您的 Nginx 设置中,您没有将请求转发到该地址。您必须将域请求与您的 Django 运行服务器相匹配,在生产中,您应该有类似 Gunicorn

的东西

试试 -

upstream backend {
    server localhost:8000;
}
server {
        server_name example.com www.example.com;
        location / {
            include proxy_params;
            proxy_pass http://backend;
     }

这适用于非 https。您可以添加 listen 443 ssl 和 SSL 证书以使您的服务器块仅侦听 HTTPS。

【讨论】:

    猜你喜欢
    • 2011-09-06
    • 2011-05-19
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    相关资源
    最近更新 更多