【发布时间】:2015-12-14 09:58:33
【问题描述】:
我正在尝试提供一个 django webapp,它使用 gunicorn 和 httpd 作为代理,它也提供静态内容。一切正常,除了 django rest 框架可搜索 API 根(应用程序 API 的入口点)没有提供正确的 url。 url 是 localhost 和 gunicorn 服务的端口,而不是机器的 ipaddress 或其主机名。这是应用程序的 httpd conf 文件:
<VirtualHost *:80>
DocumentRoot /opt/example
ProxyPass /static/ !
Alias /static/ /var/www/html/static/
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
</VirtualHost>
Gunicorn 在 localhost 的 8000 端口上提供服务。
这是 api 的视图:
@api_view(('GET',))
def api_root(request, format=None):
return Response({
'activity': reverse('activity-list', request=request, format=format)
'test' : reverse('test-list', request=request, format=format)
})
点击 api 根页面时,这是我得到的响应:
HTTP 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, HEAD, OPTIONS
{
"activity": "http://localhost:8000/activity/",
"tests": "http://localhost:8000/test/",
}
【问题讨论】:
标签: django apache proxy django-rest-framework gunicorn