简体   繁体   中英

Deploying Django with no CGI available?

I need to deploy a Django project on a shared server which I have no root access for, and no administration capabilities whatsoever.

Each user on the server has a dedicated directory from which Apache serves that users files (public URL would be /~username/ ).

Problem is, Apache on this server has no CGI capabilities, no mod_python , no mod_wsgi . I can work with PHP, however.

What hacks do I have to deploy a Django project on this server, maybe employing PHP somehow?

This is in no way a production scenario, and any hack you can think of which will work would be great. Ignore any performance or scalability factors - this is only a POC.

Without mod_python, mod_wsgi, or fastCGI, you won't be able to do it directly.

I'm thinking what you might have to do is run the django app as standalone, listening on another port, then basically use PHP to proxy requests to it.

So you do your

python manage.py runserver 9999

maybe starting it with a nohup instead to keep it running when you logout:

nohup python manage.py runserver 9999 &

Then, in ~username, you make a proxy.php script that takes any additional PATH_INFO and makes a request to localhost:9999, passing along HTTP headers, collects the response, and sends it back to the browser.

So, eg, the browser requests http://example.com/~username/proxy.php/some/path/ and the PHP script requests http://localhost:9999/some/path/ and sends along the results.

I'm not a PHP programmer so I can't exactly show you how to write that, but I'm sure someone out there must have implemented an HTTP proxy in PHP.

If you have .htaccess support in that directory and apache has mod_proxy_http enabled, you could just have apache directly proxy the request. The documentation is pretty easy to follow. But if they don't have CGI enabled, they probably don't have that set up either.

Of course, the easiest thing would be if you could just get away with django running and listening on a public facing port and access it directly. Ie,

python manage.py runserver example.com:9999

and access it directly as http://example.com:9999/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM