【问题标题】:Need help on connecting django to react using nginx and gunicorn需要帮助连接 django 以使用 nginx 和 gunicorn 做出反应
【发布时间】:2019-12-08 01:08:36
【问题描述】:

我正在尝试将 Django 后端连接到前端开发人员提供给我的 React 构建。我将 Gunicorn 用于 Django,Web 服务器是 Nginx。 下面的配置文件是大量谷歌搜索的结果。 目前 Django 后端在端口 80/8000 上工作,但是每当我将端口更改为下面的 8001 之类的任何其他端口时,服务器都不会响应。

完整的东西在 Google Ubuntu VM 上运行。 出于测试目的,我执行了sudo ufw disable

server {
    #listen 80;
    listen 8001;
    listen [::]:8001;
    server_name xx.xx.7.xx;

    location = /favicon.ico {
        access_log off;
        log_not_found off;
    }

    location /static/ {
        root /home/username/cateringm;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
    #location / {
     #   try_files $uri $uri/cm_react_build/build/index.html; # this is where you serve the React build
   # }
}
server {
    listen 8002;
    listen [::]:8002;
    server_name xx.xx.7.xx;
    root /home/username/cm_react_build/build;
    index index.html index.htm;

    location /static/ {
        root /home/username/cm_react_build/build;
    }

    location /test {
    root /home/username/cm_react_build/build;
    index index.html;

        try_files $uri $uri/ /index.html?$args;
    }
}

我是配置网络服务器的新手。帮助将不胜感激。

【问题讨论】:

    标签: django reactjs nginx gunicorn


    【解决方案1】:

    我发现了问题。默认情况下,Google 会阻止除 80 端口之外的所有端口。我更新了不同端口的防火墙规则,并且请求正在通过。

    【讨论】:

      猜你喜欢
      • 2018-04-24
      • 2023-03-19
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 2020-01-19
      相关资源
      最近更新 更多