需要帮助连接 django 以使用 nginx 和 gunicorn 做出反应

Need help on connecting django to react using nginx and gunicorn

我正在尝试将 Django 后端连接到前端开发人员提供给我的 React 构建。我正在为 Django 使用 Gunicorn,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;
    }
}

我不熟悉配置 Web 服务器。帮助将不胜感激。

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