【发布时间】:2022-11-03 16:39:49
【问题描述】:
我有一个 Django 项目,我已经使用本教程通过 gunicorn 和 nginx 在我的 Ubuntu 18.04 服务器上成功部署了该项目。
该项目使用 Django Rest Framework,我可以通过 Web 浏览器访问它的端点。但是,我还想在同一台服务器上部署一个单独的 react 项目,以便它可以向 Django 应用程序发送 http 请求并显示从 REST API 接收到的数据。我该怎么做呢?
这是我目前的gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/my_project/coffeebrewer
ExecStart=/home/ubuntu/my_project/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/my_project/coffeebrewer/coffeebrewer.sock coffeebrewer.wsgi:application
[Install]
WantedBy=multi-user.target
这是我当前的 nginx 配置
server {
listen 80;
listen [::]:80;
server_name my_ipv6_address;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root root /home/ubuntu/my_project/coffeebrewer;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
【问题讨论】:
标签: reactjs django nginx web-deployment gunicorn