Primero por si acaso hacemos esto que es para borrar el apache entero:
Código:
sudo apt-get remove apache2-* --purge
Luego por si queda algo:
Ahora hacemos update al server:
Código:
sudo apt-get update
sudo apt-get upgrade
Ahora instalamos el apache2 y el mod_wsgi:
Código:
sudo apt-get install apache2 libapache2-mod-wsgi
Suponemos que tenemos python y django instalado, si no es asi, instalarlo, es bastante facil
Ahora tocamos el fichero /etc/hosts:
Código:
cd /etc/
sudo gedit hosts &
En el fichero tiene que aparecer algo asi(adjunto mi ejemplo, podeis cambiar IP y nombre),yo lo he llamado ficherotsol.com y la ip es 10.34.112.21, es ip privada, para luego hacerla publica teneis que configurar el NAT:
Código:
127.0.0.1 localhost
127.0.1.1 ServidoTSOL
10.34.112.21 ficherotsol.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
NOTA: supongo que tenemos el proyecto django funcionando, asi que averiguamos la ruta donde se encuentra , usando en el terminal pwd, el manage.py. La mia por ejemplo es:
/home/servidortsol/ProyectosDjango/TSOL , aqui se encuentra /home/servidortsol/ProyectosDjango/TSOL/manage.py
Ahora creamos una carpeta que se llame Apache que contendra el .wsgi
Código:
mkdir /home/servidortsol/ProyectosDjango/TSOL/Apache
Ahora me creo el fichero, lo puedo hacer con touch o directamente lo abro y lo guardo asi:
Código:
sudo gedit /home/servidortsol/ProyectosDjango/TSOL/tsol.wsgi
Mi fichero tsol.wsgi contiene:(OJO IMPORTANTE EL .settings que es nuestro settings.py pero no le ponemos el .py ni toda la ruta solo donde se encuentra el manage.py)
Código:
import os, sys
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('/usr/local/lib/python2.7/dist-packages/django')
sys.path.append('/home/servidortsol/ProyectosDjango/TSOL')
sys.path.append('/home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos/Incidencias.jpg')
sys.path.append('/home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos/Peticiones.jpg')
sys.path.append('/home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos/Global.jpg')
sys.path.append('/home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos/SLA.jpg')
sys.path.append('/home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos/SLAAcumulado.jpg')
os.environ['DJANGO_SETTINGS_MODULE'] = 'TSOL.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Ahora me creo un nuevo sitio en apache para ello hago:
Código:
sudo gedit /etc/apache2/sites-available/tsol
El fichero creado tsol contendra(pongo mi ejemplo, modificar con vuestras rutas, etc)
Código:
<VirtualHost *:80>
ServerName ficherotsol.com
DocumentRoot /home/servidortsol/ProyectosDjango/TSOL/Apache
Alias /Archivos /home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos
<Directory /home/servidortsol/ProyectosDjango/TSOL/Apache>
Order allow,deny
Allow from all
</Directory>
<Directory /home/servidortsol/ProyectosDjango/TSOL/TSOL/Archivos/>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess ficherotsol.com user=www-data group=www-data processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup ficherotsol.com
WSGIScriptAlias / /home/servidortsol/ProyectosDjango/TSOL/Apache/tsol.wsgi
</VirtualHost>
Ahora activamos el sitio:
Y levantamos el apache:
Código:
sudo /etc/init.d/apache2 reload
Ahora probamos nuestra pagina http://ficherotsol.com/ y vemos que funciona nuestro proyecto django :)
NOTAS:
Si te sale algo asi:
Código:
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Para ello haz esto:
Código:
sudo gedit /etc/apache2/httpd.conf
El archivo puede estar vacio, asi que añade:
Para errores como:
no display name and no $DISPLAY environment variable, puedo poner esta linea en views.py:
Failed to create /var/www/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data (que es un error que te puede salir al usar matplotlib) , puedo poner en views.py estas lineas:
Código:
import tempfile
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
import matplotlib
import matplotlib.pyplot as plt