【发布时间】:2020-08-15 19:29:35
【问题描述】:
我使用 Linux 服务器将 React 应用程序作为前端,将 Django 作为后端。
gunicorn 配置如下:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=name
Group=www-data
WorkingDirectory=/var/www/backend/app
ExecStart=/var/www/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/name/backend.sock app.wsgi:application
[Install]
WantedBy=multi-user.target
而nginx的配置如下:
server {
listen 80;
root /var/www/frontend/build;
server_name example.com;
location = /favicon.ico { access_log off; log_not_found off; }
location / {
}
location /graphql {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
proxy_pass http://unix:/home/name/backend.sock;
}
}
Django 应用 urls.py 如下:
urlpatterns = [
path('admin/', admin.site.urls),
path('reports/', include('reports.urls')),
path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True)))
]
如果我向www.example.com/graphql 发出提取请求,它可以正常工作。
但如果我想按如下方式访问 Django 管理仪表板 www.example.com/admin/ 它不起作用。
如果我理解得很好,location /graphql {} 表示 Django 应用程序在该 url 上运行。因此,如果我想访问 urls.py 文件中的一些 url,我使用www.example.com/graphql/url from urls.py
不应该是www.example.com/graphql/graphql
如何访问管理仪表板?有什么不懂的好?
【问题讨论】:
标签: django reactjs nginx graphql gunicorn