diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index d6263b246ab..863bb2e5cdf 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -432,8 +432,8 @@ X_FRAME_OPTIONS = 'SAMEORIGIN' USE_X_FORWARDED_HOST = False -# The Python dotted path to the WSGI application that Django's internal servers -# (runserver, runfcgi) will use. If `None`, the return value of +# The Python dotted path to the WSGI application that Django's internal server +# (runserver) will use. If `None`, the return value of # 'django.core.wsgi.get_wsgi_application' is used, thus preserving the same # behavior as previous versions of Django. Otherwise this should point to an # actual WSGI application object. diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index a0c86024b99..f7504794e3d 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -233,13 +233,8 @@ class ManagementUtility(object): # special case: the 'help' subcommand has no options elif cwords[0] in subcommands and cwords[0] != 'help': subcommand_cls = self.fetch_command(cwords[0]) - # special case: 'runfcgi' stores additional options as - # 'key=value' pairs - if cwords[0] == 'runfcgi': - from django.core.servers.fastcgi import FASTCGI_OPTIONS - options.extend((k, 1) for k in FASTCGI_OPTIONS) # special case: add the names of installed apps to options - elif cwords[0] in ('dumpdata', 'sql', 'sqlall', 'sqlclear', + if cwords[0] in ('dumpdata', 'sql', 'sqlall', 'sqlclear', 'sqlcustom', 'sqlindexes', 'sqlmigrate', 'sqlsequencereset', 'test'): try: app_configs = apps.get_app_configs() diff --git a/django/core/management/commands/runfcgi.py b/django/core/management/commands/runfcgi.py deleted file mode 100644 index 98de8005031..00000000000 --- a/django/core/management/commands/runfcgi.py +++ /dev/null @@ -1,32 +0,0 @@ -import argparse -import warnings - -from django.core.management.base import BaseCommand -from django.utils.deprecation import RemovedInDjango19Warning - - -class Command(BaseCommand): - help = "Runs this project as a FastCGI application. Requires flup." - - def add_arguments(self, parser): - parser.add_argument('args', nargs=argparse.REMAINDER, - help='Various KEY=val options.') - - def handle(self, *args, **options): - warnings.warn( - "FastCGI support has been deprecated and will be removed in Django 1.9.", - RemovedInDjango19Warning) - - from django.conf import settings - from django.utils import translation - # Activate the current language, because it won't get activated later. - try: - translation.activate(settings.LANGUAGE_CODE) - except AttributeError: - pass - from django.core.servers.fastcgi import runfastcgi - runfastcgi(args) - - def usage(self, subcommand): - from django.core.servers.fastcgi import FASTCGI_HELP - return FASTCGI_HELP diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py index a6dd4d2d0e6..e4b010a4b22 100644 --- a/django/core/servers/basehttp.py +++ b/django/core/servers/basehttp.py @@ -33,13 +33,11 @@ def get_internal_wsgi_application(): this will be the ``application`` object in ``projectname/wsgi.py``. This function, and the ``WSGI_APPLICATION`` setting itself, are only useful - for Django's internal servers (runserver, runfcgi); external WSGI servers - should just be configured to point to the correct application object - directly. + for Django's internal server (runserver); external WSGI servers should just + be configured to point to the correct application object directly. If settings.WSGI_APPLICATION is not set (is ``None``), we just return whatever ``django.core.wsgi.get_wsgi_application`` returns. - """ from django.conf import settings app_path = getattr(settings, 'WSGI_APPLICATION') diff --git a/django/core/servers/fastcgi.py b/django/core/servers/fastcgi.py deleted file mode 100644 index b44473baed1..00000000000 --- a/django/core/servers/fastcgi.py +++ /dev/null @@ -1,187 +0,0 @@ -""" -FastCGI (or SCGI, or AJP1.3 ...) server that implements the WSGI protocol. - -Uses the flup python package: http://www.saddi.com/software/flup/ - -This is an adaptation of the flup package to add FastCGI server support -to run Django apps from Web servers that support the FastCGI protocol. -This module can be run standalone or from the django-admin / manage.py -scripts using the "runfcgi" directive. - -Run with the extra option "help" for a list of additional options you can -pass to this server. -""" - -import importlib -import os -import sys - -__version__ = "0.1" -__all__ = ["runfastcgi"] - -FASTCGI_OPTIONS = { - 'protocol': 'fcgi', - 'host': None, - 'port': None, - 'socket': None, - 'method': 'fork', - 'daemonize': None, - 'workdir': '/', - 'pidfile': None, - 'maxspare': 5, - 'minspare': 2, - 'maxchildren': 50, - 'maxrequests': 0, - 'debug': None, - 'outlog': None, - 'errlog': None, - 'umask': None, -} - -FASTCGI_HELP = r""" - Run this project as a fastcgi (or some other protocol supported - by flup) application. To do this, the flup package from - http://www.saddi.com/software/flup/ is required. - - runfcgi [options] [fcgi settings] - -Optional Fcgi settings: (setting=value) - protocol=PROTOCOL fcgi, scgi, ajp, ... (default %(protocol)s) - host=HOSTNAME hostname to listen on. - port=PORTNUM port to listen on. - socket=FILE UNIX socket to listen on. - method=IMPL prefork or threaded (default %(method)s). - maxrequests=NUMBER number of requests a child handles before it is - killed and a new child is forked (0 = no limit). - maxspare=NUMBER max number of spare processes / threads (default %(maxspare)s). - minspare=NUMBER min number of spare processes / threads (default %(minspare)s). - maxchildren=NUMBER hard limit number of processes / threads (default %(maxchildren)s). - daemonize=BOOL whether to detach from terminal. - pidfile=FILE write the spawned process-id to this file. - workdir=DIRECTORY change to this directory when daemonizing (default %(workdir)s). - debug=BOOL set to true to enable flup tracebacks. - outlog=FILE write stdout to this file. - errlog=FILE write stderr to this file. - umask=UMASK umask to use when daemonizing, in octal notation (default 022). - -Examples: - Run a "standard" fastcgi process on a file-descriptor - (for Web servers which spawn your processes for you) - $ manage.py runfcgi method=threaded - - Run a scgi server on a TCP host/port - $ manage.py runfcgi protocol=scgi method=prefork host=127.0.0.1 port=8025 - - Run a fastcgi server on a UNIX domain socket (posix platforms only) - $ manage.py runfcgi method=prefork socket=/tmp/fcgi.sock - - Run a fastCGI as a daemon and write the spawned PID in a file - $ manage.py runfcgi socket=/tmp/fcgi.sock method=prefork \ - daemonize=true pidfile=/var/run/django-fcgi.pid - -""" % FASTCGI_OPTIONS - - -def fastcgi_help(message=None): - print(FASTCGI_HELP) - if message: - print(message) - return False - - -def runfastcgi(argset=[], **kwargs): - options = FASTCGI_OPTIONS.copy() - options.update(kwargs) - for x in argset: - if "=" in x: - k, v = x.split('=', 1) - else: - k, v = x, True - options[k.lower()] = v - - if "help" in options: - return fastcgi_help() - - try: - import flup # NOQA - except ImportError as e: - sys.stderr.write("ERROR: %s\n" % e) - sys.stderr.write(" Unable to load the flup package. In order to run django\n") - sys.stderr.write(" as a FastCGI application, you will need to get flup from\n") - sys.stderr.write(" http://www.saddi.com/software/flup/ If you've already\n") - sys.stderr.write(" installed flup, then make sure you have it in your PYTHONPATH.\n") - return False - - flup_module = 'server.' + options['protocol'] - - if options['method'] in ('prefork', 'fork'): - wsgi_opts = { - 'maxSpare': int(options["maxspare"]), - 'minSpare': int(options["minspare"]), - 'maxChildren': int(options["maxchildren"]), - 'maxRequests': int(options["maxrequests"]), - } - flup_module += '_fork' - elif options['method'] in ('thread', 'threaded'): - wsgi_opts = { - 'maxSpare': int(options["maxspare"]), - 'minSpare': int(options["minspare"]), - 'maxThreads': int(options["maxchildren"]), - } - else: - return fastcgi_help("ERROR: Implementation must be one of prefork or " - "thread.") - - wsgi_opts['debug'] = options['debug'] is not None - - try: - module = importlib.import_module('.%s' % flup_module, 'flup') - WSGIServer = module.WSGIServer - except Exception: - print("Can't import flup." + flup_module) - return False - - # Prep up and go - from django.core.servers.basehttp import get_internal_wsgi_application - - if options["host"] and options["port"] and not options["socket"]: - wsgi_opts['bindAddress'] = (options["host"], int(options["port"])) - elif options["socket"] and not options["host"] and not options["port"]: - wsgi_opts['bindAddress'] = options["socket"] - elif not options["socket"] and not options["host"] and not options["port"]: - wsgi_opts['bindAddress'] = None - else: - return fastcgi_help("Invalid combination of host, port, socket.") - - if options["daemonize"] is None: - # Default to daemonizing if we're running on a socket/named pipe. - daemonize = (wsgi_opts['bindAddress'] is not None) - else: - if options["daemonize"].lower() in ('true', 'yes', 't'): - daemonize = True - elif options["daemonize"].lower() in ('false', 'no', 'f'): - daemonize = False - else: - return fastcgi_help("ERROR: Invalid option for daemonize " - "parameter.") - - daemon_kwargs = {} - if options['outlog']: - daemon_kwargs['out_log'] = options['outlog'] - if options['errlog']: - daemon_kwargs['err_log'] = options['errlog'] - if options['umask']: - daemon_kwargs['umask'] = int(options['umask'], 8) - - if daemonize: - from django.utils.daemonize import become_daemon - become_daemon(our_home_dir=options["workdir"], **daemon_kwargs) - - if options["pidfile"]: - with open(options["pidfile"], "w") as fp: - fp.write("%d\n" % os.getpid()) - - WSGIServer(get_internal_wsgi_application(), **wsgi_opts).run() - -if __name__ == '__main__': - runfastcgi(sys.argv[1:]) diff --git a/django/utils/daemonize.py b/django/utils/daemonize.py deleted file mode 100644 index 76f4d5d082d..00000000000 --- a/django/utils/daemonize.py +++ /dev/null @@ -1,62 +0,0 @@ -import os -import sys - -from . import six - -buffering = int(six.PY3) # No unbuffered text I/O on Python 3 (#20815). - -if os.name == 'posix': - def become_daemon(our_home_dir='.', out_log='/dev/null', - err_log='/dev/null', umask=0o022): - "Robustly turn into a UNIX daemon, running in our_home_dir." - # First fork - try: - if os.fork() > 0: - sys.exit(0) # kill off parent - except OSError as e: - sys.stderr.write("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror)) - sys.exit(1) - os.setsid() - os.chdir(our_home_dir) - os.umask(umask) - - # Second fork - try: - if os.fork() > 0: - os._exit(0) - except OSError as e: - sys.stderr.write("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror)) - os._exit(1) - - si = open('/dev/null', 'r') - so = open(out_log, 'a+', buffering) - se = open(err_log, 'a+', buffering) - os.dup2(si.fileno(), sys.stdin.fileno()) - os.dup2(so.fileno(), sys.stdout.fileno()) - os.dup2(se.fileno(), sys.stderr.fileno()) - # Set custom file descriptors so that they get proper buffering. - sys.stdout, sys.stderr = so, se -else: - def become_daemon(our_home_dir='.', out_log=None, err_log=None, umask=0o022): - """ - If we're not running under a POSIX system, just simulate the daemon - mode by doing redirections and directory changing. - """ - os.chdir(our_home_dir) - os.umask(umask) - sys.stdin.close() - sys.stdout.close() - sys.stderr.close() - if err_log: - sys.stderr = open(err_log, 'a', buffering) - else: - sys.stderr = NullDevice() - if out_log: - sys.stdout = open(out_log, 'a', buffering) - else: - sys.stdout = NullDevice() - - class NullDevice: - "A writeable object that writes to nowhere -- like /dev/null." - def write(self, s): - pass diff --git a/docs/howto/deployment/fastcgi.txt b/docs/howto/deployment/fastcgi.txt deleted file mode 100644 index 848d296b600..00000000000 --- a/docs/howto/deployment/fastcgi.txt +++ /dev/null @@ -1,431 +0,0 @@ -============================================ -How to use Django with FastCGI, SCGI, or AJP -============================================ - -.. deprecated:: 1.7 - FastCGI support is deprecated and will be removed in Django 1.9. - -.. highlight:: bash - -Although :doc:`WSGI` is the preferred deployment -platform for Django, many people use shared hosting, on which protocols such as -FastCGI, SCGI or AJP are the only viable options. - -.. admonition:: Note - - This document primarily focuses on FastCGI. Other protocols, such as SCGI - and AJP, are also supported, through the ``flup`` Python package. See the - Protocols_ section below for specifics about SCGI and AJP. - -Essentially, FastCGI is an efficient way of letting an external application -serve pages to a Web server. The Web server delegates the incoming Web requests -(via a socket) to FastCGI, which executes the code and passes the response back -to the Web server, which, in turn, passes it back to the client's Web browser. - -Like WSGI, FastCGI allows code to stay in memory, allowing requests to be -served with no startup time. While -e.g. :doc:`mod_wsgi` can either be configured -embedded in the Apache Web server process or as a separate daemon process, a -FastCGI process never runs inside the Web server process, always in a separate, -persistent process. - -.. _mod_perl: http://perl.apache.org/ - -.. admonition:: Why run code in a separate process? - - The traditional ``mod_*`` arrangements in Apache embed various scripting - languages (most notably PHP, Python and Perl) inside the process space of - your Web server. Although this lowers startup time -- because code doesn't - have to be read off disk for every request -- it comes at the cost of - memory use. - - Due to the nature of FastCGI, it's even possible to have processes that run - under a different user account than the Web server process. That's a nice - security benefit on shared systems, because it means you can secure your - code from other users. - -Prerequisite: flup -================== - -Before you can start using FastCGI with Django, you'll need to install flup_, a -Python library for dealing with FastCGI. Version 0.5 or newer should work fine. - -.. _flup: http://www.saddi.com/software/flup/ - -Starting your FastCGI server -============================ - -FastCGI operates on a client-server model, and in most cases you'll be starting -the FastCGI process on your own. Your Web server (be it Apache, lighttpd, or -otherwise) only contacts your Django-FastCGI process when the server needs a -dynamic page to be loaded. Because the daemon is already running with the code -in memory, it's able to serve the response very quickly. - -.. admonition:: Note - - If you're on a shared hosting system, you'll probably be forced to use - Web server-managed FastCGI processes. See the section below on running - Django with Web server-managed processes for more information. - -A Web server can connect to a FastCGI server in one of two ways: It can use -either a Unix domain socket (a "named pipe" on Win32 systems), or it can use a -TCP socket. What you choose is a manner of preference; a TCP socket is usually -easier due to permissions issues. - -To start your server, first change into the directory of your project (wherever -your :doc:`manage.py ` is), and then run the -:djadmin:`runfcgi` command:: - - ./manage.py runfcgi [options] - -If you specify ``help`` as the only option after :djadmin:`runfcgi`, it'll -display a list of all the available options. - -You'll need to specify either a :djadminopt:`socket`, a :djadminopt:`protocol` -or both :djadminopt:`host` and :djadminopt:`port`. Then, when you set up your -Web server, you'll just need to point it at the host/port or socket you -specified when starting the FastCGI server. See the examples_, below. - -Protocols ---------- - -Django supports all the protocols that flup_ does, namely fastcgi_, `SCGI`_ and -`AJP1.3`_ (the Apache JServ Protocol, version 1.3). Select your preferred -protocol by using the :djadminopt:`protocol=\ ` option -with ``./manage.py runfcgi`` -- where ```` may be one of: -``fcgi`` (the default), ``scgi`` or ``ajp``. For example:: - - ./manage.py runfcgi protocol=scgi - -.. _flup: http://www.saddi.com/software/flup/ -.. _fastcgi: http://www.fastcgi.com/ -.. _SCGI: http://python.ca/scgi/protocol.txt -.. _AJP1.3: http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html - -Examples --------- - -Running a threaded server on a TCP port:: - - ./manage.py runfcgi method=threaded host=127.0.0.1 port=3033 - -Running a preforked server on a Unix domain socket:: - - ./manage.py runfcgi method=prefork socket=/home/user/mysite.sock pidfile=django.pid - -.. admonition:: Socket security - - Django's default umask requires that the web server and the Django fastcgi - process be run with the same group **and** user. For increased security, - you can run them under the same group but as different users. If you do - this, you will need to set the umask to 0002 using the ``umask`` argument - to ``runfcgi``. - -Run without daemonizing (backgrounding) the process (good for debugging):: - - ./manage.py runfcgi daemonize=false socket=/tmp/mysite.sock maxrequests=1 - -Stopping the FastCGI daemon ---------------------------- - -If you have the process running in the foreground, it's easy enough to stop it: -Simply hitting ``Ctrl-C`` will stop and quit the FastCGI server. However, when -you're dealing with background processes, you'll need to resort to the Unix -``kill`` command. - -If you specify the :djadminopt:`pidfile` option to :djadmin:`runfcgi`, you can -kill the running FastCGI daemon like this:: - - kill `cat $PIDFILE` - -...where ``$PIDFILE`` is the ``pidfile`` you specified. - -To easily restart your FastCGI daemon on Unix, try this small shell script:: - - #!/bin/bash - - # Replace these three settings. - PROJDIR="/home/user/myproject" - PIDFILE="$PROJDIR/mysite.pid" - SOCKET="$PROJDIR/mysite.sock" - - cd $PROJDIR - if [ -f $PIDFILE ]; then - kill `cat -- $PIDFILE` - rm -f -- $PIDFILE - fi - - exec /usr/bin/env - \ - PYTHONPATH="../python:.." \ - ./manage.py runfcgi socket=$SOCKET pidfile=$PIDFILE - -Apache setup -============ - -To use Django with Apache and FastCGI, you'll need Apache installed and -configured, with `mod_fastcgi`_ installed and enabled. Consult the Apache -documentation for instructions. - -Once you've got that set up, point Apache at your Django FastCGI instance by -editing the ``httpd.conf`` (Apache configuration) file. You'll need to do two -things: - -* Use the ``FastCGIExternalServer`` directive to specify the location of - your FastCGI server. -* Use ``mod_rewrite`` to point URLs at FastCGI as appropriate. - -.. _mod_fastcgi: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html - -Specifying the location of the FastCGI server ---------------------------------------------- - -The ``FastCGIExternalServer`` directive tells Apache how to find your FastCGI -server. As the `FastCGIExternalServer docs`_ explain, you can specify either a -``socket`` or a ``host``. Here are examples of both: - -.. code-block:: apache - - # Connect to FastCGI via a socket / named pipe. - FastCGIExternalServer /home/user/public_html/mysite.fcgi -socket /home/user/mysite.sock - - # Connect to FastCGI via a TCP host/port. - FastCGIExternalServer /home/user/public_html/mysite.fcgi -host 127.0.0.1:3033 - -In either case, the file ``/home/user/public_html/mysite.fcgi`` doesn't -actually have to exist. It's just a URL used by the Web server internally -- a -hook for signifying which requests at a URL should be handled by FastCGI. (More -on this in the next section.) - -.. _FastCGIExternalServer docs: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer - -Using mod_rewrite to point URLs at FastCGI ------------------------------------------- - -The second step is telling Apache to use FastCGI for URLs that match a certain -pattern. To do this, use the `mod_rewrite`_ module and rewrite URLs to -``mysite.fcgi`` (or whatever you specified in the ``FastCGIExternalServer`` -directive, as explained in the previous section). - -In this example, we tell Apache to use FastCGI to handle any request that -doesn't represent a file on the filesystem and doesn't start with ``/media/``. -This is probably the most common case, if you're using Django's admin site: - -.. code-block:: apache - - - ServerName example.com - DocumentRoot /home/user/public_html - Alias /media /home/user/python/django/contrib/admin/media - RewriteEngine On - RewriteRule ^/(media.*)$ /$1 [QSA,L,PT] - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^/(.*)$ /mysite.fcgi/$1 [QSA,L] - - -.. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html - -Django will automatically use the pre-rewrite version of the URL when -constructing URLs with the :ttag:`{% url %}` template tag (and similar -methods). - -Using mod_fcgid as alternative to mod_fastcgi ----------------------------------------------- - -Another way to serve applications through FastCGI is by using Apache's -`mod_fcgid`_ module. Compared to mod_fastcgi mod_fcgid handles FastCGI -applications differently in that it manages the spawning of worker processes -by itself and doesn't offer something like ``FastCGIExternalServer``. This -means that the configuration looks slightly different. - -In effect, you have to go the way of adding a script handler similar to what -is described later on regarding running Django in a :ref:`shared-hosting -environment `. For further details please refer to the -`mod_fcgid reference`_ - -.. _mod_fcgid: http://httpd.apache.org/mod_fcgid/ -.. _mod_Fcgid reference: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html - -lighttpd setup -============== - -lighttpd_ is a lightweight Web server commonly used for serving static files. It -supports FastCGI natively and, thus, is a good choice for serving both static -and dynamic pages, if your site doesn't have any Apache-specific needs. - -.. _lighttpd: http://www.lighttpd.net/ - -Make sure ``mod_fastcgi`` is in your modules list, somewhere after -``mod_rewrite`` and ``mod_access``, but not after ``mod_accesslog``. You'll -probably want ``mod_alias`` as well, for serving admin media. - -Add the following to your lighttpd config file: - -.. code-block:: lua - - server.document-root = "/home/user/public_html" - fastcgi.server = ( - "/mysite.fcgi" => ( - "main" => ( - # Use host / port instead of socket for TCP fastcgi - # "host" => "127.0.0.1", - # "port" => 3033, - "socket" => "/home/user/mysite.sock", - "check-local" => "disable", - ) - ), - ) - alias.url = ( - "/media" => "/home/user/django/contrib/admin/media/", - ) - - url.rewrite-once = ( - "^(/media.*)$" => "$1", - "^/favicon\.ico$" => "/media/favicon.ico", - "^(/.*)$" => "/mysite.fcgi$1", - ) - -Running multiple Django sites on one lighttpd ---------------------------------------------- - -lighttpd lets you use "conditional configuration" to allow configuration to be -customized per host. To specify multiple FastCGI sites, just add a conditional -block around your FastCGI config for each site:: - - # If the hostname is 'www.example1.com'... - $HTTP["host"] == "www.example1.com" { - server.document-root = "/foo/site1" - fastcgi.server = ( - ... - ) - ... - } - - # If the hostname is 'www.example2.com'... - $HTTP["host"] == "www.example2.com" { - server.document-root = "/foo/site2" - fastcgi.server = ( - ... - ) - ... - } - -You can also run multiple Django installations on the same site simply by -specifying multiple entries in the ``fastcgi.server`` directive. Add one -FastCGI host for each. - -Cherokee setup -============== - -Cherokee is a very fast, flexible and easy to configure Web Server. It -supports the widespread technologies nowadays: FastCGI, SCGI, PHP, CGI, SSI, -TLS and SSL encrypted connections, Virtual hosts, Authentication, on the fly -encoding, Load Balancing, Apache compatible log files, Data Base Balancer, -Reverse HTTP Proxy and much more. - -The Cherokee project provides a documentation to `setting up Django`_ with Cherokee. - -.. _setting up Django: http://www.cherokee-project.com/doc/cookbook_django.html - -.. _apache_shared_hosting: - -Running Django on a shared-hosting provider with Apache -======================================================= - -Many shared-hosting providers don't allow you to run your own server daemons or -edit the ``httpd.conf`` file. In these cases, it's still possible to run Django -using Web server-spawned processes. - -.. admonition:: Note - - If you're using Web server-spawned processes, as explained in this section, - there's no need for you to start the FastCGI server on your own. Apache - will spawn a number of processes, scaling as it needs to. - -In your Web root directory, add this to a file named ``.htaccess``: - -.. code-block:: apache - - AddHandler fastcgi-script .fcgi - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L] - -Then, create a small script that tells Apache how to spawn your FastCGI -program. Create a file ``mysite.fcgi`` and place it in your Web directory, and -be sure to make it executable:: - - #!/usr/bin/python - import sys, os - - # Add a custom Python path. - sys.path.insert(0, "/home/user/python") - - # Switch to the directory of your project. (Optional.) - # os.chdir("/home/user/myproject") - - # Set the DJANGO_SETTINGS_MODULE environment variable. - os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings" - - from django.core.servers.fastcgi import runfastcgi - runfastcgi(method="threaded", daemonize="false") - -This works if your server uses mod_fastcgi. If, on the other hand, you are -using mod_fcgid the setup is mostly the same except for a slight change in the -``.htaccess`` file. Instead of adding a fastcgi-script handler, you have to -add a fcgid-handler: - -.. code-block:: apache - - AddHandler fcgid-script .fcgi - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L] - -Restarting the spawned server ------------------------------ - -If you change any Python code on your site, you'll need to tell FastCGI the -code has changed. But there's no need to restart Apache in this case. Rather, -just reupload ``mysite.fcgi``, or edit the file, so that the timestamp on the -file will change. When Apache sees the file has been updated, it will restart -your Django application for you. - -If you have access to a command shell on a Unix system, you can accomplish this -easily by using the ``touch`` command:: - - touch mysite.fcgi - -Serving admin media files -========================= - -Regardless of the server and configuration you eventually decide to use, you -will also need to give some thought to how to serve the admin media files. The -advice given in the :ref:`mod_wsgi ` documentation -is also applicable in the setups detailed above. - -Forcing the URL prefix to a particular value -============================================ - -Because many of these fastcgi-based solutions require rewriting the URL at -some point inside the Web server, the path information that Django sees may not -resemble the original URL that was passed in. This is a problem if the Django -application is being served from under a particular prefix and you want your -URLs from the :ttag:`{% url %}` tag to look like the prefix, rather than -the rewritten version, which might contain, for example, ``mysite.fcgi``. - -Django makes a good attempt to work out what the real script name prefix -should be. In particular, if the Web server sets the ``SCRIPT_URL`` (specific -to Apache's mod_rewrite), or ``REDIRECT_URL`` (set by a few servers, including -Apache + mod_rewrite in some situations), Django will work out the original -prefix automatically. - -In the cases where Django cannot work out the prefix correctly and where you -want the original value to be used in URLs, you can set the -:setting:`FORCE_SCRIPT_NAME` setting in your main ``settings`` file. This sets the -script name uniformly for every URL served via that settings file. Thus you'll -need to use different settings files if you want different sets of URLs to -have different script names in this case, but that is a rare situation. - -As an example of how to use it, if your Django configuration is serving all of -the URLs under ``'/'`` and you wanted to use this setting, you would set -``FORCE_SCRIPT_NAME = ''`` in your settings file. diff --git a/docs/howto/deployment/index.txt b/docs/howto/deployment/index.txt index 7b37a4870ec..db2b7d0676d 100644 --- a/docs/howto/deployment/index.txt +++ b/docs/howto/deployment/index.txt @@ -12,13 +12,6 @@ ways to easily deploy Django: wsgi/index checklist -FastCGI support is deprecated and will be removed in Django 1.9. - -.. toctree:: - :maxdepth: 1 - - fastcgi - If you're new to deploying Django and/or Python, we'd recommend you try :doc:`mod_wsgi ` first. In most cases it'll be the easiest, fastest, and most stable deployment choice. diff --git a/docs/howto/deployment/wsgi/index.txt b/docs/howto/deployment/wsgi/index.txt index 128e296ad66..105825b7b41 100644 --- a/docs/howto/deployment/wsgi/index.txt +++ b/docs/howto/deployment/wsgi/index.txt @@ -36,10 +36,10 @@ It's used both by Django's development server and in production WSGI deployments. WSGI servers obtain the path to the ``application`` callable from their -configuration. Django's built-in servers, namely the :djadmin:`runserver` and -:djadmin:`runfcgi` commands, read it from the :setting:`WSGI_APPLICATION` -setting. By default, it's set to ``.wsgi.application``, which -points to the ``application`` callable in :file:`/wsgi.py`. +configuration. Django's built-in server, namely the :djadmin:`runserver` +command, read it from the :setting:`WSGI_APPLICATION` setting. By default, it's +set to ``.wsgi.application``, which points to the ``application`` +callable in :file:`/wsgi.py`. Configuring the settings module ------------------------------- diff --git a/docs/index.txt b/docs/index.txt index f4074ca5f2b..c3a91c48a81 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -205,7 +205,6 @@ testing of Django applications: * **Deployment:** :doc:`Overview ` | :doc:`WSGI servers ` | - :doc:`FastCGI/SCGI/AJP ` (deprecated) | :doc:`Deploying static files ` | :doc:`Tracking code errors by email ` diff --git a/docs/man/django-admin.1 b/docs/man/django-admin.1 index 243a15edf57..f683742a94f 100644 --- a/docs/man/django-admin.1 +++ b/docs/man/django-admin.1 @@ -64,11 +64,6 @@ Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for project and application) directory. .TP -.BI "runfcgi [" "KEY=val" "] [" "KEY=val" "] " "..." -Runs this project as a FastCGI application. Requires flup. Use -.B runfcgi help -for help on the KEY=val pairs. -.TP .BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "port|ipaddr:port" "]" Starts a lightweight Web server for development. .TP diff --git a/docs/ref/contrib/gis/deployment.txt b/docs/ref/contrib/gis/deployment.txt index f90c9c2e91d..3c8b415a0ff 100644 --- a/docs/ref/contrib/gis/deployment.txt +++ b/docs/ref/contrib/gis/deployment.txt @@ -11,8 +11,7 @@ the deployment of a normal Django application. Please consult Django's GeoDjango uses the GDAL geospatial library which is not thread safe at this time. Thus, it is *highly* recommended to not use threading when deploying -- in other words, use an - appropriate configuration of Apache or the prefork method - when using FastCGI through another Web server. + appropriate configuration of Apache. For example, when configuring your application with ``mod_wsgi``, set the ``WSGIDaemonProcess`` attribute ``threads`` to ``1``, unless diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 570766f18d4..d343a19205f 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -775,133 +775,6 @@ run correctly. The ``--list`` option has been moved to the :djadmin:`showmigrations` command. -runfcgi [options] ------------------ - -.. django-admin:: runfcgi - -.. deprecated:: 1.7 - FastCGI support is deprecated and will be removed in Django 1.9. - -Starts a set of FastCGI processes suitable for use with any Web server that -supports the FastCGI protocol. See the :doc:`FastCGI deployment documentation -` for details. Requires the Python FastCGI module from -`flup`_. - -Internally, this wraps the WSGI application object specified by the -:setting:`WSGI_APPLICATION` setting. - -.. _flup: http://www.saddi.com/software/flup/ - -The options accepted by this command are passed to the FastCGI library and -don't use the ``'--'`` prefix as is usual for other Django management commands. - -.. django-admin-option:: protocol - -``protocol=PROTOCOL`` - -Protocol to use. *PROTOCOL* can be ``fcgi``, ``scgi``, ``ajp``, etc. -(default is ``fcgi``) - -.. django-admin-option:: host - -``host=HOSTNAME`` - -Hostname to listen on. - -.. django-admin-option:: port - -``port=PORTNUM`` - -Port to listen on. - -.. django-admin-option:: socket - -``socket=FILE`` - -UNIX socket to listen on. - -.. django-admin-option:: method - -``method=IMPL`` - -Possible values: ``prefork`` or ``threaded`` (default ``prefork``) - -.. django-admin-option:: maxrequests - -``maxrequests=NUMBER`` - -Number of requests a child handles before it is killed and a new child is -forked (0 means no limit). - -.. django-admin-option:: maxspare - -``maxspare=NUMBER`` - -Max number of spare processes / threads. - -.. django-admin-option:: minspare - -``minspare=NUMBER`` - -Min number of spare processes / threads. - -.. django-admin-option:: maxchildren - -``maxchildren=NUMBER`` - -Hard limit number of processes / threads. - -.. django-admin-option:: daemonize - -``daemonize=BOOL`` - -Whether to detach from terminal. - -.. django-admin-option:: pidfile - -``pidfile=FILE`` - -Write the spawned process-id to file *FILE*. - -.. django-admin-option:: workdir - -``workdir=DIRECTORY`` - -Change to directory *DIRECTORY* when daemonizing. - -.. django-admin-option:: debug - -``debug=BOOL`` - -Set to true to enable flup tracebacks. - -.. django-admin-option:: outlog - -``outlog=FILE`` - -Write stdout to the *FILE* file. - -.. django-admin-option:: errlog - -``errlog=FILE`` - -Write stderr to the *FILE* file. - -.. django-admin-option:: umask - -``umask=UMASK`` - -Umask to use when daemonizing. The value is interpreted as an octal number -(default value is ``0o22``). - -Example usage:: - - django-admin runfcgi socket=/tmp/fcgi.sock method=prefork daemonize=true \ - pidfile=/var/run/django-fcgi.pid - -Run a FastCGI server as a daemon and write the spawned PID in a file. - runserver [port or address:port] -------------------------------- diff --git a/docs/releases/1.3.txt b/docs/releases/1.3.txt index aecab5e332e..6b947a16e7b 100644 --- a/docs/releases/1.3.txt +++ b/docs/releases/1.3.txt @@ -692,8 +692,7 @@ more flexible ``mod_wsgi`` backend. If you are currently using the ``mod_python`` request handler, you should redeploy your Django projects using another request handler. :doc:`mod_wsgi ` is the request handler -recommended by the Django project, but :doc:`FastCGI -` is also supported. Support for +recommended by the Django project, but FastCGI is also supported. Support for ``mod_python`` deployment will be removed in Django 1.5. Function-based generic views diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt index 811b800bb08..0917ce6ee0b 100644 --- a/docs/releases/1.4.txt +++ b/docs/releases/1.4.txt @@ -220,7 +220,7 @@ with the same WSGI configuration that is used for deployment. The new :setting:`WSGI_APPLICATION` setting lets you configure which WSGI callable :djadmin:`runserver` uses. -(The :djadmin:`runfcgi` management command also internally wraps the WSGI +(The ``runfcgi`` management command also internally wraps the WSGI callable configured via :setting:`WSGI_APPLICATION`.) ``SELECT FOR UPDATE`` support diff --git a/docs/spelling_wordlist b/docs/spelling_wordlist index 7efc687e171..5b8d89330c6 100644 --- a/docs/spelling_wordlist +++ b/docs/spelling_wordlist @@ -199,9 +199,7 @@ Facebook fallback fallbacks faq -fastcgi FastCGI -fcgid fieldset fieldsets filesizeformat @@ -540,7 +538,6 @@ rjust roadmap Roald rss -runfcgi runserver SaaS safeseq diff --git a/tests/.coveragerc b/tests/.coveragerc index ef4b90d22ee..753386b21a7 100644 --- a/tests/.coveragerc +++ b/tests/.coveragerc @@ -1,5 +1,5 @@ [run] -omit = */django/contrib/*/tests*,*/django/core/servers/fastcgi.py,*/django/utils/autoreload.py +omit = */django/contrib/*/tests*,*/django/utils/autoreload.py [report] ignore_errors = True diff --git a/tests/bash_completion/tests.py b/tests/bash_completion/tests.py index f8f1fe4553b..c43c0483b50 100644 --- a/tests/bash_completion/tests.py +++ b/tests/bash_completion/tests.py @@ -93,12 +93,6 @@ class BashCompletionTests(unittest.TestCase): output = self._run_autocomplete() self.assertEqual(output, ['']) - def test_runfcgi(self): - "Command arguments will be autocompleted" - self._user_input('django-admin runfcgi h') - output = self._run_autocomplete() - self.assertEqual(output, ['host=']) - def test_app_completion(self): "Application names will be autocompleted for an AppCommand" self._user_input('django-admin sqlmigrate a')