【发布时间】:2018-03-31 13:38:48
【问题描述】:
我为我的 Django 应用程序创建了一个 rest API,但是我如何访问 api.website.com 而不是 www.website.com/api 之类的东西
顺便说一句,我正在使用 nginx,如果这需要做任何事情的话
【问题讨论】:
标签: python django url nginx django-urls
我为我的 Django 应用程序创建了一个 rest API,但是我如何访问 api.website.com 而不是 www.website.com/api 之类的东西
顺便说一句,我正在使用 nginx,如果这需要做任何事情的话
【问题讨论】:
标签: python django url nginx django-urls
在您的 nginx 配置中添加类似这样的内容。这会将 api.website.com 上的所有请求传递到您的 gunicorn 套接字 -> 您的 django 应用程序。
server {
listen *:80;
server_name api.website.com;
location ~ ^/api(.*)$ {
try_files $uri $1 /$1;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://gunicorn_socket/;
}
}
【讨论】: