nginx serving Django in a subdirectory through uWSGI

前端 未结 5 2020
别跟我提以往
别跟我提以往 2021-02-19 15:48

I have already gone through some previous threads: How do I set subdirectory in nginx with Django how to deploy django under a suburl behind nginx Serving flask app on subdirect

5条回答
  •  时光说笑
    2021-02-19 16:18

    If the application is so simple that a simple "/prefix" can be added to one line in urls.py then I prefer this simple solution without anything more.

    Otherwise the "/prefix" must be appended to the domain column in the record for your site in Sites table in Django admin. The domain should be then "example.com/project" with the second solution, because Django must know the domain and the prefix, especially for correct redirect. Naturally the prefix must be also stripped from URL of the request by webserver, as you do it now in nginx settings.

    I usually split the verification of such deployments to two questions:

    • Does report the web server (nginx) the expected shorter or longer URLs to Django?
    • Does know Django its full base URL and does it use that in all web pages consistently?

    I use both nginx log and Django logging enabled to see which of them is eventually miscofigured. (You didn't wrote enough important information.)

    An important case that should be tested is: Verify that web pages that require athentication are redirected to login page correctly back and forth, even if you try these URLs after logout.

    More details can be found in the similar question.

提交回复
热议问题