Hi, guys, my django app is using 2 domains, but one of them needs to be for the django admin or any other urls and not the main website.
How i can solve this?, im using gunicorn and nginx.
Thank you
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
It’s hard to give you a good answer without some more details about your project. If both domains are part of the same project, you’ll probably need to use something like Django’s “sites framework" in order to direct requests correctly. Is this something you are already doing?
Using gunicorn, you’ll need to run a seperate processes for each site as each will have it’s own settings file. For instance, to run the admin portal on a separate domain you could create a settings_admin.py like:
from settings import *
ROOT_URLCONF = 'urls_admin'
And an urls_admin.py file like:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'', include(admin.site.urls)),
)
Then launch the gunicorn processes (of course you’ll want to set this up with Upstart or supervisord in production):
gunicorn_django -w 2 -b 127.0.0.1:9000 /path/to/project/settings_admin.py --daemon
gunicorn_django -w 2 -b 127.0.0.1:9001 /path/to/project/settings.py --daemon
Then you need to configure Nginx:
upstream admin_site {
server 127.0.0.1:9000 fail_timeout=0;
}
upstream main_site {
server 127.0.0.1:900` fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
client_max_body_size 4G;
server_name admin-site.com;
keepalive_timeout 5;
location /media {
alias /path/to/media;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://admin_site;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
client_max_body_size 4G;
server_name main-site.com;
keepalive_timeout 5;
location /media {
alias /path/to/media;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://main_site;
}
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.