gpt4 book ai didi

django - 如何仅将子域关联到我在 Digital Ocean 上的 Django 应用程序?

转载 作者:行者123 更新时间:2023-12-04 10:56:16 24 4
gpt4 key购买 nike

我们已经有一个网站叫X.com .现在我正在一个 digital ocean 液滴上构建一个 Django 应用程序。我可以使用 IP 地址访问它。
但我们希望将其命名为 reporting.X.com与我们的用户分享。
在我的域提供商上,我已经添加了如下所示的 A 记录

Host- reporting
Type - A
Content - <ip-address> of digital ocean droplet

但是,当我尝试访问 reporting.X.com 时,我不断收到以下消息.
我该怎么办?
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

最佳答案

好的,我已经解决了这个问题。所以我会回答这个问题以供其他人将来引用。

您需要检查 2 个重要的地方。

  • /etc/nginx/sites-enabled/<your_project>

  • 如果您希望 django 应用程序只包含子域,则启用站点的项目文件应如下所示。
    server {
    listen 80;
    server_name <ip-address> .X.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
    root /home/<user>/<project>;
    }

    location / {
    include proxy_params;
    proxy_pass http://unix:/home/<user>/<project>.sock;
    }
    dot前面 X.com不是错别字。这基本上表示 X.com 的任何子域.
  • settings.py Django 应用程序中的文件

  • 您必须设置 ALLOWED_HOSTS这边走。 ALLOWED_HOSTS = ['ip-address', '.X.com']再次 X.com前面带有 dot .

    在问题中,我已经提到我创建了一个 A记录以下细节。
    Host- reporting
    Type - A
    Content - <ip-address> of digital ocean droplet

    在此之后,重新启动您的 nginx 服务器。 sudo systemctl restart nginx
    现在,理论上它应该可以工作。但如果没有(因为对我来说没有), 您必须关闭并重新启动您的 Droplet。
    sudo shutdown -r now
    在此事件后,我的 Django 应用程序开始工作。
    希望能帮助到你。

    关于django - 如何仅将子域关联到我在 Digital Ocean 上的 Django 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59165664/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com