I'm new to Django...
I need to start a project that will have subdomains, but I'm little confused about this subject...
I will have a website serving Spain, other serving United Kingdom and other serving United States and I will use only one domain and 3 subdomains, just like this:
Main domain:
mysite.com
Subdomains:
es.mysite.com
uk.mysite.com
us.mysite.com
These 3 different site in future could have to scale, each one in one dedicated server, but for now these 3 websites will use the same server.
In a previous question I was told to use a middleware solution(http://thingsilearned.com/2009/01/05/using-subdomains-in-django/) but I don't konw if it this that I need. With this solution if I need to scale the websites for dedicated servers each one I think will not work...
It is possible to define instead the subdomains in Apache Virtual Hosts? What do you think of using 3 different Django projects with Apache Virtual Hosts will doing the job? This is a better solution or I should go with middleware?
Best Regards,
If you're looking to expand the subdomains to different servers eventually, the easier solution will probably be using virtual hosts on your web server.
Each host can just use a separate settings module (they can all import * from a common settings module, changing any database / language settings which are specific to that domain).
Deploying this way means you have a higher memory usage, since you will be dealing with separate instances for each domain, but that doesn't sound like it will be a problem for you and your long term direction. It also makes things simpler, using middleware can get messy (especially with tests and the like).
Related
TLDR:
Would a "real server" (Apache? Flask? Django?) be able to unify various services behind readable subdirectories (abc.work.com/svn, abc.work.com/hg) instead of using port numbers (abc.work.com:8000, abs.work.com:8001)?
Long Version:
In the last year I've learned how to serve files with Mongoose, run a minimal python webserver, host version control repositories with Subversion and Mercurial, and host a Trac issue tracker/project management framework.
In each case I've been using the easy built-in webserver provided by each tool to host it from my Windows 7 laptop at work (I'm an engineer who codes, not actually paid to be a "software guy"). In order to avoid clashing I've used different port numbers in the 8000 range for each server to listen on, and sent my coworkers links like http://machinename.domain.com:8042 to access these magical things I've created.
The first obvious problem is that I'm running a lot of these things out of a command prompt and just letting it sit open on my desktop. I also know how to call cmd.exe from VBScript in order to hide the command prompt if that's all I wanted. Many of the built-in webservers even have options to run as a service, which can get harry with permissions, but is closer to the "right" way to host a server of any kind.
The bigger problem is that I'm sending people links to my machine with different port numbers. I'm ok with them having to use my machine name - I assume I'd need the network admin folks to add a DNS entry to call it TeamAwesome.company.com instead of machinename.company.com:8000?
The bigger question is, if I did something fancy like an Apache, Django, or Flask webserver, could I set it up like machinename.company.com/trac for the trac server and machinename.company.com/hg/project1 for the HG repository for project1? I'm looking at Apache, Django, and Flask because I've been diving into Python for 2 years now and those appear the most applicable/approachable for my needs.
I understand that ideally this stuff should be hosted on a separate linux-y server machine, but I'll need to prove the usefulness of the tools I'm developing before I request server resources from my boss (who hired me to do engineering, not programming, or web development, or systems administration, etc.).
I see this looks related. Are http proxies, virtual hosts, nginx, and WebSockets things to look at?
Looking at Apache VirtualHost examples looks promising though I can't decipher if one of those examples actually does what I'm talking about. Thanks for any suggestions as I go further down the rabbit hole with this stuff!
Apache virtual hosts can be differentiated by listening ip and/or port number only.
The mod_proxy module can do what you want if you want/have those services to be running separately as well:
ProxyRequests Off
<Proxy *>
Allow from all
</Proxy>
ProxyPass /folder_a http://backend_a:1234/ retry=5
ProxyPass /folder_b http://backend_b:8888/ retry=5
# etc
However if you just want to point different urls to point to unrelated folders on your server then check the Location and Alias directives
No need for proxy settings. You can use a single virtual server, but run each application under a certain subdirectory: for example, with Django or another wsgi app, you would simply set WSGIScriptAlias to the relevant dir.
A big clarification, though: Django is not in any way a server. In fact, you need Apache or an equivalent in order to serve Django properly.
I am developing a web app using django for server-side. It has clients in android, ios and frontend. I was thinking of using subdomains for differentiating the urls of these clients. The differentiation is due to the fact that responses to urls are different for different clients.
I was hoping of being able to do using subdomains like android.example.com, ios.example.com...etc. My subdomains are fixed.
Can you help regarding what approach I should take to achieve this. Some options I have read are
Hosting two different project with same database.(Looks quite good for me, but may not be the optimum)
Hosting on same instance using sites framework.(Not sure as to how good this option is)
Hosting using virtual-host(Really Not able to understand how to achieve this).
Using a Sub-domain Middleware, as mentioned in many of answers and also in some Django Snippets.
Please help me with the best option and if possible with links to some tutorials as to how to achieve it. Thanks.
"Using the sites framework" is somehow the same as hosting two projects with the same database. If you would use the sites framework you would have seperate instances for each subdomain which share the same code base and data base, but have to differ in one setting in the first place, which is SITE_ID.
If you're able to run multiple instances this for sure has some advantages:
You don't need additional processing via a middleware
You can easily choose different settings for each site, eg. different template paths, use different middleware etc, even customize urls per project if necessary
You're doing already some kind of load-balancing, as you're directing requests to seperate instances, also if one site crashes it shouldn't affect the others
If you can only run one instance I guess your only choice is using something like a middleware, eg. django-mobile then is maybe something to look in as it offers you some good toolset for determining the type of client etc...
But besides that note that it might not always be the best practice to have seperate domains with the same content when it comes to SEO.
I started develop two sites separately, but now I need to merge them (so http://site1.com/site2) points to site2 (which has a separate settings.py).
I could probably refactor the code and make site2 an app of site1, but I suspect there is an easy way. Also, site2 uses a different database, and I don't intend to mix up both databases...
If I want to use subdomain (like site2.site1.com), will it make it easier?
Any suggestion? Thanks.
The easiest way to do this is to leave both Django applications separate but present them as one site using a reverse proxy such as nginx. The applications will live on separate servers or at least be served on the same server on separate ports, and nginx will proxy requests to one application or the other based on what path is requested.
What I'm trying to do is best explained by looking how wordpress.com works:
each blog is assigned to a new subdomain, but users can use their own domain as well. Custom domains could be assigned using a simple web interface
each blog has its own contents, theme, etc
all blogs share the same codebase
Is it possible to do the same thing in Django?
I'm not interested in implementing subdomains, but I want the other features.
It is important to me to find a way that domains don't have to be hardcoded in a configuration file in order to work. The dynamic nature of domain assignment makes managing large number of domains possible. It would be ideal if domain matching could be done against a database table.
I use nginx and uwsgi.
Yes but it will require more work in Django compared to out-of-the box Wordpress install but will offer you more flexibility.
You might want to take a look at django sites. However I don't think it will be able to do everything you are trying to do.
A more modular system would be for you to write a script which when invoked will bootstrap a new db schema, new virtuelenv, install all necessary things into it, add a site config for the new site to nginx/apache and then restart the nginx/apache. The code can be from the same directories, except since each site will run on it's own virtualenv, it will be much more secure, reliable and fault tolerant. This however as you can see will require some work but I depending on your requirements, it is the most flexible way.
I run a small VPS with 512M memory of memory that currently hosts 3 very low traffic PHP sites and a personal email account.
I have been teaching myself Django over the last few weeks and am starting to think about deploying a project.
There seem to be a very large number of methods for deploying a Django site. Given the limited resources I have available, what would be the most appropriate option?
Will the VPS be suitable to host both python and PHP sites or would it be worth getting a separate server?
Any advice appreciated.
Thanks.
There aren't really a great number of ways to do it. In fact, there's the recommended way - via Apache/mod_wsgi - and all the other ways. The recommended way is fully documented here.
For a low-traffic site, you should have no trouble fitting it in your 512MB VPS along with your PHP sites.
Django has documentation describing possible server arrangements. For light weight, yet very robust set up, I'd recommend Nginx setup. It's much lighter than Apache.
I run several low-traffic Django sites on a 256 VPS without problem. I have Nginx setup as a reverse proxy and to serve static files (javascript, CSS, images) and Apache using mod_wsgi for serving Django as described in the documentation.
Running PHP sites as well may add a little overhead, but, if you're talking about low-traffic "fun" sites then you should be fine.