VirtualHost for django site on dedicated server with multiple web sites - django

So, i'm trying to run Django web site on my dedicated server which has multiple sites on itself and its folder structure looks like this:
home/user/www/
site1/
site2/
site3/
mydjangosite.com/
site1, site2 etc. are php/html web sites, and of course i need to keep them runing, so i'm wondering how should i configure my httpd.conf because these lines below are not working:
<VirtualHost *:80>
DocumentRoot home/user/www/mydjangosite.com
ServerName mydjangosite
WSGIScriptAlias / home/user/www/mydjangosite.com/testing/wsgi.py
<Directory "home/user/www/mydjangosite.com/testing">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EDIT
I've modified my httpd.conf and instead of lines above (with VirtualHost *:80) i've added next:
WSGIScriptAlias / /home/user/www/mydjangosite.com/testing/wsgi.py
WSGIPythonPath /home/user/www/mydjangosite.com
<Directory /home/user/www/mydjangosite.com/testing>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
and finally i've got Django succes page:
It worked!
Congratulations on your first Django-powered page.
But now i get that Django page for every domain that is on my server.

Try this:
<VirtualHost *:80>
DocumentRoot /home/user/www/mydjangosite.com
ServerName mydjangosite
WSGIScriptAlias / /home/user/www/mydjangosite.com/testing/wsgi.py
<Directory "/home/user/www/mydjangosite.com/testing">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Instead of:
<VirtualHost *:80>
DocumentRoot home/user/www/mydjangosite.com
ServerName mydjangosite
WSGIScriptAlias / home/user/www/mydjangosite.com/testing/wsgi.py
<Directory "home/user/www/mydjangosite.com/testing">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Related

Django project set up with Apache2 - i want to access it through I.P/application_name/

Hi I want to set up my django project to be access through apache2 by I.P/application_name/
So "192.0.0.0/app/" (Ip being an example)
Here is my 000-default.conf file in etc/apache2/sites-available
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess HTSv2 python-home=/home/django/config/env python-path=/usr/local/django/app
WSGIProcessGroup HTSv2
WSGIScriptAlias / /usr/local/django/app/application/wsgi.py
<Directory /usr/local/django/app/application>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /usr/local/django/app/static/
<Directory /usr/local/django/app/static>
Require all granted
</Directory>
<Directory /usr/local/django/app>
Deny from all
Allow from ...
</Directory>
</VirtualHost>
When I change the line:
WSGIScriptAlias / /usr/local/django/app/application/wsgi.py
to
WSGIScriptAlias /app/ /usr/local/django/app/application/wsgi.py
I can access the home page of my application by 192.0.0.0/app/
However when I click on any buttons, obviously does not keep to this, so for example going to page1, does not go to 192.0.0.0/app/page1, it goes to 192.0.0.0/page1
How can I configure apache2 to do this? The reason I want to do this is so I can host multiple projects on the same server, so the root of 1 project is 192.0.0.0/app1/ and then the root of the other is 192.0.0.0/app2/ etc...

How do I receive subdomain wildcards on Apache2 using mod wsgi?

I'm developing an app with Django 1.8 and I'm trying to receive subdomains and then present customized homepages dependent on the subdomain. For example: example.com is my company's homepage, a user signs up as conqueryor.example.com and they get a new homepage named "conqueryor.example.com" or whatever they want.
Sounds simple enough, there's even the django subdomains library that I'm using. My current issue lies in setting up Apache2 and mod WSGI locally so that I can test it out locally before I affect everyone else on the project. I'm currently able to use the following .conf file with the lines 127.0.0.1 example.dev and 127.0.0.1 .example.dev in my /etc/hosts file. In my browser I'm able to access my app from example.dev, but if I try any subdomains I receive the Server Not Found page. I've also attempted using dnsmasq and adding the line address=/.example.dev/127.0.0.1
Current environment:
Ubuntu 15.10
Django 1.8.1
Apache 2.4
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /home/example
ServerAlias www.example.dev
WSGIDaemonProcess example python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example
WSGIScriptAlias / /home/example/saas/wsgi.py
<Directory /home/example/static>
Require all granted
</Directory>
<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /home/example
ServerAlias example.dev
WSGIDaemonProcess example2 python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example2
WSGIScriptAlias / /home/example/saas/wsgi.py
Alias /static/ /home/example/static/
<Directory /home/example/static>
Require all granted
</Directory>
<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /home/example
ServerAlias *.example.dev
WSGIDaemonProcess example3 python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example3
WSGIScriptAlias / /home/example/saas/wsgi.py
Alias /static/ /home/example/static/
<Directory /home/example/static>
Require all granted
</Directory>
<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Thanks!
I'm going to leave the question in case this helps anyone else, but I found the solution... I forgot I hadn't restarted dnsmasq, so after adding the address=/.example.dev/127.0.0.1 line to /etc/dnsmasq.conf and restarting dnsmasq with sudo /etc/init.d/dnsmasq restart I was able to access sites on subdomains. Oops!

VirtualHost configuration doesn't allow second website to run

I have this in my /etc/apache2/sites-available/staginnx.com.conf
WSGIScriptAlias / /home/ubuntu/v1/staginnx-info/app/website/website/wsgi.py
WSGIPythonPath /home/ubuntu/v1/staginnx-info/app/website
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin info#staginnx.com
ServerName staginnx.com
ServerAlias www.staginnx.com
<Directory /home/ubuntu/v1/staginnx-info/app/website/website>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /home/ubuntu/v1/staginnx-info/app/website/ui/static/
<Directory /home/ubuntu/v1/staginnx-info/app/website/ui/static>
Require all granted
</Directory>
Alias /favicon.ico /home/ubuntu/v1/staginnx-info/app/website/ui/static/images/favicon.ico
ErrorLog /var/log/apache2/error.log
</VirtualHost>
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin blog.staginnx#staginnx.com
ServerName blog.staginnx.com
ServerAlias blog.staginnx.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/html/blog/
<Directory /var/www/html/blog>
Require all granted
</Directory>
# Custom log file locations
LogLevel warn
ErrorLog /var/www/html/blog/log/error.log
CustomLog /var/www/html/blog/log/access.log combined
</VirtualHost>
Now the first one, the main website is working fine. The second one, BLOG is not working.
I have done sudo a2ensite staginnx.com.conf and a symlink is generated at sites-enabled. I have done reload apache and restart too.
Surfed around but no luck.
Want to install wordpress blog in my blog folder.
In order to use your django application inside a virtual host you need to set the WSGIScriptAlias inside the virtualhost settings and also you can't use the WSGIPythonPath, you need to use WSGIDaemonProcess like in the following settings.
<VirtualHost *:80>
WSGIScriptAlias / /home/ubuntu/v1/staginnx-info/app/website/website/wsgi.py
WSGIDaemonProcess example.com python-path=/home/ubuntu/v1/staginnx-info/app/website
# Admin email, Server Name (domain name) and any aliases
ServerAdmin info#staginnx.com
ServerName staginnx.com
ServerAlias www.staginnx.com
<Directory /home/ubuntu/v1/staginnx-info/app/website/website>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /home/ubuntu/v1/staginnx-info/app/website/ui/static/
<Directory /home/ubuntu/v1/staginnx-info/app/website/ui/static>
Require all granted
</Directory>
Alias /favicon.ico /home/ubuntu/v1/staginnx-info/app/website/ui/static/images/favicon.ico
ErrorLog /var/log/apache2/error.log
</VirtualHost>
Also in case you want to host multiple application on the same host then you need to change a small setting in the wsgi.py file as well.
instead of using
os.environ.setdefault(DJANGO_SETTINGS_MODULE, "app.settings")
you should use
os.environ["DJANGO_SETTINGS_MODULE"] = "app.settings"
I hope this helps you.
For WSGIDaemonProcess setting

2 Djangos 1 Server

I have Deployed several projects of mine onto my new server. What seems to be happening is I can view one project fine, but once I go to the next one, the settings for the previous project are still being used.
For example, jacobvalenta.net and dev.pawndaddy.org are both projects on the server, flipping between the two can result in the settings getting mixed up.
SGIPythonPath /home/projects/pawndaddy:/home/projects/jacobvalenta:/home/projects/sailcast:/home/projects/tryfecta:/home/projects/midiscribe
NameVirtualHost *:80
<VirtualHost *:80>
ServerName jacobvalenta.net
ServerAlias *.jacobvalenta.net
DocumentRoot /home/projects/jacobvalenta
WSGIScriptAlias / /home/projects/jacobvalenta/jacobvalenta/wsgi.py
<Directory /home/projects/jacobvalenta/jacobvalenta>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName sailcast.org
ServerAlias *.sailcast.org
DocumentRoot /home/projects/sailcast
WSGIScriptAlias / /home/projects/sailcast/sailcast/wsgi.py
<Directory /home/projects/sailcast/sailcast>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName pawndaddy.org
ServerAlias *.pawndaddy.org
DocumentRoot /home/projects/pawndaddy/
WSGIScriptAlias / /home/projects/pawndaddy/pawndaddy/wsgi.py
<Directory /home/projects/pawndaddy/pawndaddy>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
I should have read the files a little bit more!
Within wsgi.py, the comments say:
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "project.settings"
so just remove the line about setting the default environment, and all should be good.

Deploying multiple django projects on apache with mod_wsgi

I'm trying to deploy 2 django projects on Apache with mod_wsgi using daemon mode, but right now I just get 404's when I try to load the pages.
The two sites are hosted on the same server, both on port 80. The two entries in sites-avalable are below:
<VirtualHost *:80>
ServerAdmin admin#site1.com
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /var/www/site1.com
ErrorLog /srv/www/site1.com/logs/error.log
CustomLog /srv/www/site1.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.org
ServerName site2.org
ServerAlias www.site2.org
DocumentRoot /var/www/site2.org
ErrorLog /srv/www/site2.org/logs/error.log
CustomLog /srv/www/site2.org/logs/access.log combined
</VirtualHost>
And in my httpd.conf,
WSGIDaemonProcess site1.com python-path=/usr/local/www/site1/
WSGIProcessGroup site1.com
WSGIScriptAlias site1.com/blog /usr/local/www/site1/site1/wsgi.py
WSGIDaemonProcess site2.org python-path=/usr/local/www/site2/
WSGIProcessGroup site2.org
WSGIScriptAlias site2.org/ /usr/local/www/site2/site2/wsgi.py
<Directory /usr/local/www/site1/site1>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Directory /usr/local/www/site2/site2>
<Files wsgi.py>
Order deny, allow
Allow from all
</Files>
</Directory>
I took the httpd.conf stuff right out of the Django docs, but it's still not working properly. site1.com/blog gives me a 404, and site2.org gives me a generic Apache filetree. What am I missing here?
If you have a sites-available directory, you're on a Debian-derived distro, and you shouldn't be editing httpd.conf at all. All the stuff that you've put into httpd.conf should go in the relevant files in sites-available.