Need help configuring apache .conf file - django

I want to deploy my django app on a Apache 2.4 server. The same server will host static files. The thing is that this server hosts other php based web sites.
In order for all this to work I just need to install mod_wsgi and configure apache's .conf file related to this web site, is that right?
After reading few articles I came up with this config, assuming that the web site will be in the var/www/ folder :
<VirtualHost *:80>
ServerName example.com
# Alias /events /var/www/events/html
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example
Alias /media/ /var/www/example/media/
Alias /static/ /var/www/example/static/
<Directory /var/www/example/static>
Order deny,allow
Require all granted
</Directory>
<Directory /path/to/example/media>
Order deny,allow
Require all granted
</Directory>
WSGIScriptAlias / /var/www/example/events_promgruz/wsgi.py
WSGIDaemonProcess example.com python-path=/var/www/example:/opt/envs/lib/python3.6/site-packages
WSGIProcessGroup example.com
<Directory /path/to/example/example>
<Files wsgi.py>
Order allow,deny
Require all granted
</Files>
</Directory>
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What would you suggested to change or add to config?
Is there some other steps to ensure that django app will work and that it doesn't interfere other non wsgi apps?

This is what I ended up using:
<VirtualHost *:80>
ServerName expample-domen.com
ServerAdmin webmaster#localhost
Alias /static /var/www/example/static
Alias /media /var/www/example/media
<Directory /var/www/example/static>
Require all granted
</Directory>
<Directory /var/www/example/media>
Order deny,allow
Require all granted
</Directory>
<Directory /var/www/example/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess example python-home=/path/to/virtualEnv python-path=/var/www/example
WSGIProcessGroup example
WSGIScriptAlias / /var/www/example/example/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Related

How to fix? Error 500: No WSGI daemon process called... (Apache/ Django)

I have an internal Server Error 500 on my Django Server. When I check the error.log, I get the following error:
No WSGI daemon process called "..." has been configured: "..."
I hope someone can help me to fix this Error.
Here is my Apache config:
<VirtualHost *:80>
ServerAdmin ADMIN
ServerName DOMAIN
ErrorLog /home/USER/PROJECT/site/logs/error.log
CustomLog /home/PROJECT/PROJECT/site/logs/access.log combined
Alias /static /home/USER/PROJECT/static
<Directory /home/USER/PROJECT/static>
Require all granted
</Directory>
<Directory /home/USER/PROJECT/src/social>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess PROJECT python-path=/home/USER/PROJECT/ python-home=/home/USER/PROJECT/VIRTUALENV
WSGIProcessGroup PROJECT
WSGIScriptAlias / /home/USER/PROJECT/src/social/wsgi.py
</VirtualHost>
move your project path from /home/USER/PROJECT to /var/www/PROJECT
make sure you are chmod project folder --> sudo chmod -R 777 /project
if not work give your email to me for contact
<VirtualHost *:80>
# edit all /home/USER/PROJECT to /var/www/PROJECT
ServerAdmin ADMIN
ServerName DOMAIN
ErrorLog /home/USER/PROJECT/site/logs/error.log
CustomLog /home/PROJECT/PROJECT/site/logs/access.log combined
Alias /static /home/USER/PROJECT/static
<Directory /home/USER/PROJECT/static>
Require all granted
</Directory>
<Directory /home/USER/PROJECT/src/social> # here put path of where wsgi.py existing folder
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess PROJECT python-path=/home/USER/PROJECT/ python-home=/home/USER/PROJECT/VIRTUALENV
WSGIProcessGroup PROJECT
WSGIScriptAlias / /home/USER/PROJECT/src/social/wsgi.py
</VirtualHost>

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...

Multiple django projects with different domains on one server

I am trying to run two different django projects one the same server, with two different domains. Django version is 1.8, and the webserver is Apache 2.4.7.
These are my conf files in sites-available:
#example.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
ServerAdmin admin#example.com
WSGIDaemonProcess example.com python-path=/path/example/WebPortal:/path/example/venv/lib/python3.4/site-packages
WSGIProcessGroup example.com
WSGIPassAuthorization On
WSGIScriptAlias / /path/example/WebPortal/WebPortal/wsgi.py
WSGIApplicationGroup %{GLOBAL}
<Directory /path/example/WebPortal/WebPortal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /robots.txt /path/example/WebPortal/static/robots.txt
Alias /favicon.ico /path/example/WebPortal/static/favicon.ico
Alias /media/ /path/example/WebPortal/media/
Alias /static/ /path/example/WebPortal/static/
<Directory /path/example/WebPortal/static>
Require all granted
Options -Indexes
</Directory>
<Directory /path/example/WebPortal/media>
Require all granted
Options -Indexes
</Directory>
ErrorLog "/path/example/WebPortal/logs/webportal-error.log"
CustomLog "/path/example/WebPortal/logs/webportal-access.log" combined
CustomLog "/path/example/WebPortal/logs/webportal-bandwidth.log" common
and:
#sub.example2.conf
<VirtualHost *:80>
ServerName sub.example2.com
ServerAlias sub.example2.com
ServerAdmin admin#example2.com
WSGIDaemonProcess sub.example2.com python-path=/path/sub_example2/WebPortal:/path/sub_example2/venv/lib/python3.4/site-packages
WSGIProcessGroup sub.example2.com
WSGIPassAuthorization On
WSGIScriptAlias / /path/sub_example2/WebPortal/WebPortal/wsgi.py
WSGIApplicationGroup %{GLOBAL}
<Directory /path/sub_example2/WebPortal/WebPortal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /robots.txt /path/sub_example2/WebPortal/static/robots.txt
Alias /favicon.ico /path/sub_example2/WebPortal/static/favicon.ico
Alias /media/ /path/sub_example2/WebPortal/media/
Alias /static/ /path/sub_example2/WebPortal/static/
<Directory /path/sub_example2/WebPortal/static>
Require all granted
Options -Indexes
</Directory>
<Directory /path/sub_example2/WebPortal/media>
Require all granted
Options -Indexes
</Directory>
ErrorLog "/path/sub_example2/WebPortal/logs/webportal-error.log"
CustomLog "/path/sub_example2/WebPortal/logs/webportal-access.log" combined
CustomLog "/path/sub_example2/WebPortal/logs/webportal-bandwidth.log" common
With this configuration when I enable both, only one domain work properly...on the other one I get a Bad Request (400).
I have tried many options but no one work.
Any ideas?

run multiple django project in different virtualenv on apache

I want to run two different django_projects each in different virtualenv.
This is the code :
ServerName ubuntu_server_apache
<VirtualHost *:80>
ServerName dev.hexxie.com
ErrorLog "/home/ashish/deployments/mysite_dev/conf/mysite_dev_error.log"
WSGIScriptAlias / /home/ashish/deployments/mysite_dev/mysite/mysite/wsgi.py
Alias /static /home/ashish/deployments/mysite_dev/static_root
<Directory /home/ashish/deployments/mysite_dev/static_root>
Require all granted
</Directory>
Alias /media /home/ashish/deployments/mysite_prod/data/media
<Directory /home/ashish/deployments/mysite_prod/data/media>
Require all granted
</Directory>
<Directory /home/ashish/deployments/mysite_dev/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
WSGIPythonPath /home/ashish/deployments/mysite_dev/mysite:/home/ashish/.virtualenvs/mysite_dev/lib/python2.7/site-packages
<VirtualHost *:80>
ServerName hexxie.com
ServerAlias *.hexxie.com
ErrorLog "/home/ashish/deployments/mysite_prod/conf/mysite_error.log"
WSGIScriptAlias / /home/ashish/deployments/mysite_prod/mysite/mysite/wsgi.py
Alias /static /home/ashish/deployments/mysite_prod/static_root
<Directory /home/ashish/deployments/mysite_prod/static_root>
Require all granted
</Directory>
Alias /media /home/ashish/deployments/mysite_prod/data/media
<Directory /home/ashish/deployments/mysite_prod/data/media>
Require all granted
</Directory>
<Directory /home/ashish/deployments/mysite_prod/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
WSGIPythonPath /home/ashish/deployments/mysite_prod/mysite:/home/ashish/.virtualenvs/mysite_prod/lib/python2.7/site-packages
But I am getting internal server error using this apache conf. I feel that this is due to WSGIPythonPath used twice in conf. WSGIPythonPath can't be included inside virtualhost. So how to run two diff django project each on diff virtualenv on apache ?
For a start, use a daemon process group so each runs in a separate process and then use the python-home option on the respective WSGIDaemonProcess group directives. See:
http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html
Here's an example of how I do it. You'll have to change paths / project names based on your setup, naturally (example is SSL on port 443, but works on port 80 as well):
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule ssl_module modules/mod_ssl.so
WSGISocketPrefix /var/run/wsgi
NameVirtualHost *:443
Listen 443
<VirtualHost *:443>
ServerName your.server.com
ErrorLog /home/user/apache_errors.log
WSGIDaemonProcess project1-https python-home=/home/user/.virtualenvs/project1
WSGIScriptAlias /project1 /var/www/html/project1/project1/wsgi.py process-group=project1-https application-group=project1-https
WSGIProcessGroup project1-https
Alias /project1/static/ /var/www/html/project1/static/
WSGIDaemonProcess project2-https python-home=/home/user/.virtualenvs/project2
WSGIScriptAlias /project2 /var/www/html/project2/project2/wsgi.py process-group=project2-https application-group=project2-https
WSGIProcessGroup project2-https
Alias /project2/static/ /var/www/html/project2/static/
</VirtualHost>
The virtualenv takes care of the Python executable and path when configured in this manner.

Apache vhosting ubuntu one named entry serving all urls

I have 2 URL's and two django webapps to serve. Using the following example configuration, a get request for www.server2.com results in the page for www.server1.com.
Example Incoming URLS: ( verified in apache logs)
www.server1.com
www.server2.com
vhost confs:
* server1
<VirtualHost *:80>
ServerName www.server1.com
ErrorLog /.../apache/error.log
AliasMatch ^/([^/]*\.css) /opt/ef/static/css/$1
<Directory "/.../apache">
Allow from all
</Directory>
Alias /media/ /...f/media/
Alias /static/ /...f/static/
<Directory /.../static>
Order deny,allow
Allow from all
</Directory>
<Directory /../media>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
WSGIScriptAlias / /...apache/server.wsgi
**server2
<VirtualHost *:80>
ServerName www.server2.com
ErrorLog /.../apache/error.log
AliasMatch ^/([^/]*\.css) /opt/ef/static/css/$1
<Directory "/.../apache">
Allow from all
</Directory>
Alias /media/ /...f/media/
Alias /static/ /...f/static/
<Directory /.../static>
Order deny,allow
Allow from all
</Directory>
<Directory /../media>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
WSGIScriptAlias / /...apache/server.wsgi
Am I matching incorrectly?