【问题标题】:how to change www to something else in Django urls?如何在 Django url 中将 www 更改为其他内容?
【发布时间】:2018-03-31 13:38:48
【问题描述】:

我为我的 Django 应用程序创建了一个 rest API,但是我如何访问 api.website.com 而不是 www.website.com/api 之类的东西

顺便说一句,我正在使用 nginx,如果这需要做任何事情的话

【问题讨论】:

    标签: python django url nginx django-urls


    【解决方案1】:

    在您的 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/;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-21
      • 2013-04-04
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 2021-03-14
      相关资源
      最近更新 更多