Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:27:49+00:00 2026-05-20T18:27:49+00:00

I have a Django based CMS that uses Django’s sites framework and Nginx/Apache/mod_wsgi virtual

  • 0

I have a Django based CMS that uses Django’s sites framework and Nginx/Apache/mod_wsgi virtual hosts to run a number of websites on different domains. We’re assessing other options for a Django stack and have the CMS running with a single site on a new server with Nginx proxying to Gunicorn (gunicorn_django, specifically).

Although this works great for a single site, I’m not sure how to configure Gunicorn for multiple sites. The problem is that with Apache/mod_wsgi, we could set the DJANGO_SETTINGS_MODULE for mod_wsgi to the appropriate site’s settings.py

import os, sys

def inflight(filename):
    """
    Calculate absolute path to the folder containing "myfile.wsgi", then
    append to the PYTHONPATH.
    """
    ROOT = ('/').join(os.path.abspath(os.path.dirname(filename)).split('/')[0:-1])
    sys.path.append(ROOT)
    sys.path.append(os.path.join(ROOT, 'website'))

    sys.stdout = sys.stderr
    # Each website should have a settings file: /www/mysite.com/website/settings.py
    os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'
    import django.core.handlers.wsgi
    return django.core.handlers.wsgi.WSGIHandler()

At the moment I’m thinking that I have to have a different instance of Gunicorn for each virtual host site we run but that seems overkill for the traffic we get to most of our sites.

Does anyone run Gunicorn with Django’s sites framework and can give a hint to how it’s configured?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:27:50+00:00Added an answer on May 20, 2026 at 6:27 pm

    I had the same problem and stumbled upon this question in search of the same answer.

    I know the question is old and you’ve probably figured it out by now, but since it might be useful for someone else, here’s how I solved it:

    • You do need to run separate gunicorn processes to make django sites framework work because you can only point a gunicorn instance at one settings.py file. If you’re sites don’t get much traffic, I’d only create 1 or 2 gunicorn workers per site. (I know, still probably overkill).

    • Ideally you would want to manage these different processes with something like supervisord to make it easier to manage starting/stoping/restarting your different sites, but I couldn’t get it working.

    First, start up your gunicorn servers on local host at different ports using the command line. Ex:

    gunicorn_django -w 2 -b 127.0.0.1:1000 /path/to/my/django/project/site1_settings.py –daemon

    gunicorn_django -w 2 -b 127.0.0.1:1001 /path/to/my/django/project/site2_settings.py –daemon

    You now have 2 django sites running on localhost at ports 1000 and 1001 (you can use whatever ports suite you).

    Now you need to create two separate nginx server configuration files to point each domain name at it’s respective django site.
    Ex:

    server {
        listen 80;
        server_name website1.com;
        client_max_body_size 4G;
    
        keepalive_timeout 4;
    
        location /media {
            root /path/to/my/django/project/media; #this servers your static files
        }
    
        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://127.0.0.1:1000; #point to the django site already running on local host
                break;
            }
        }
    
        #add in any additional nginx configuration such as support for 500 errors or proxy apache to server php files etc.
    }
    

    Then create a duplicate of the nginx configuration for your 2nd site, but change the server name and the proxy_pass to the values for site 2.

    Make sure your server configuration files are included in the main nginx.conf file.

    Reload nginx and you should be good to go.

    If anyone has an easier/better way to go about this please post it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django form that uses a different number of fields based on
I have a Django app running on Windows (via Apache + mod_wsgi) that's CPU-bound.
I have Django running in Apache via mod_wsgi. I believe Django is caching my
I have few simple django-based sites and I their number increasing all the time.
I have a text area in a django based website that displays the content
I have a URL in a Django based web app that looks similar to
I'm developing a CMS (with Django, but that doesn't matter) and have chosen GIT.
Have django serving different settings file & database based on subdomains. The virtual host
I have two sites say foo.com and bar.com and are both Django based. Primary
I have a Django-based web application that is required to send a confirmation email

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.