how to deploy django under a suburl behind nginx

后端 未结 3 561
别那么骄傲
别那么骄傲 2020-12-08 15:16

I have a django application running on http://localhost:12345 . I\'d like user to access it via url http://my.server.com/myapp . I use nginx to reverse proxy to it like the

3条回答
  •  长情又很酷
    2020-12-08 15:17

    Here is part of my config for nginx which admittedly doesn't set FORCE_SCRIPT_NAME, but then, I'm not using a subdirectory. Maybe it will be useful for setting options related to USE_X_FORWARDED_HOST in nginx rather than Django.

    upstream app_server_djangoapp {
        server localhost:8001 fail_timeout=0;
    }
    
    server  {
        listen xxx.xxx.xx.xx:80;
        server_name mydomain.com www.mydomain.com;
        if ($host = mydomain.com) {
            rewrite ^/(.*)$ http://www.mydomain.com/$1 permanent;
        }
        ...
        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
    
            if (!-f $request_filename) {
                proxy_pass http://app_server_djangoapp;
                break;
            }
        }
        ...
    }
    

提交回复
热议问题