Django/mod_wsgi AH01630: client denied by server configuration - python

I am in the process of moving my Django site to Amazon EC2 and trying to configure Apache2 on Ubuntu 14.04.2 LTS.
When accessing the site I am getting an error:
[Sat Nov 28 05:55:54.799020 2015] [authz_core:error] [pid 1657] [client 110.143.63.231:65129] AH01630: client denied by server configuration: /home/directory/django.wsgi
My django.wsgi file is:
import os
import sys
sys.path.append('/home/directory/')
sys.path.append('/home/directory/directory/directory/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' # this is your settings.py file
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
My 000-default.conf file is:
<VirtualHost *:80>
ServerName ip.add.res.s
ServerAlias www.ip.add.res.s
ServerAdmin example#email.com
Alias /static/ /home/directory/static/
<Directory "/static/">
Options -Indexes
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /media/ /home/directory/media/
<Directory "/media/">
Options -Indexes
Order allow,deny
Allow from all
Require all granted
</Directory>
WSGIScriptAlias / /home/directory/directory/directory/django.wsgi
<Directory "/home/directory/directory/directory">
<Files django.py>
Options All
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Files>
</Directory>
</VirtualHost>
I have 755permissions on django.wsgi and the ip address is set in ALLOWED_HOSTS = []
Have been struggling on finding a solution to this.

I think you might have to include WSGI file if you are using one. wsgi.py

Related

Deploying Multiple Django Websites with Apache & mod_wsgi Windows

I am using mod_wsgi in a virtualenv with Apache 2.4 and I want to serve multiple Django sites from the same server.
httpd.config
### Configuration Site_1
LoadModule wsgi_module " S:/Site_1/VirtualEnvSite_1/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIApplicationGroup %{GLOBAL}
WSGIPythonHome "c:/users/mmyuser/appdata/local/programs/python/python36"
WSGIScriptAlias / " S:/Site_1/site_1/site_1/wsgi_windows.py"
WSGIPythonPath " S:/Site_1/VirtualEnvSite_1/Lib/site-packages"
Alias /static " S:/Site_1/site_1/staticfiles"
Alias /media " S:/Site_1/site_1/media"
<Directory " S:/Site_1/site_1/staticfiles">
Require all granted
</Directory>
<Directory " S:/Site_1/site_1/media">
Require all granted
</Directory>
<Directory " S:/Site_1/site_1/PEQ">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
####Configuration Site_2
LoadModule wsgi_module " S:/Site_2/VirtualEnvSite_2/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIApplicationGroup %{GLOBAL}
WSGIPythonHome "c:/users/myuser/appdata/local/programs/python/python36"
WSGIScriptAlias / " S:/Site_2/site_2/site_2/wsgi_windows.py"
WSGIPythonPath " S:/Site_2/VirtualEnvSite_2/Lib/site-packages"
Alias /static " S:/Site_2/site_2/staticfiles"
Alias /media " S:/Site_2/site_2/media"
<Directory " S:/Site_2/site_2/staticfiles">
Require all granted
</Directory>
<Directory " S:/Site_2/site_2/media">
Require all granted
</Directory>
<Directory " S:/Site_2/site_2/site_2">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
httpd-vhosts.config
# Virtual Hosts
#
<VirtualHost *:8080>
ServerAdmin webmaster#localhost
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
I have reviewed these posts:
Deploying multiple django apps on Apache with mod_wsgi
multiple-django-sites-with-apache-mod-wsgi
running-multiple-django-projects-on-one-apache-instance-with-mod_wsgi/
MĂșltiples direcciones, un solo proyecto
how-to-use-mod-wsgi-for-hosting-multiple-django-projects-under-single-domain
but they have not worked for me.
The server is a Windows Server 2012R2
Please direct me what I should do to get both sites up and running.
Note: The websites work perfectly separate
I also have a similar problem. And I've already looked for many posts, one thing I noticed different from yours was the line:
WSGIScriptAlias / " S:/Site_1/site_1/site_1/wsgi_windows.py"
WSGIScriptAlias / " S:/Site_2/site_2/site_2/wsgi_windows.py"
I identify the site in the alias:
WSGIScriptAlias /site1 " S:/Site_1/site_1/site_1/wsgi_windows.py"
WSGIScriptAlias /site2 " S:/Site_2/site_2/site_2/wsgi_windows.py"
And I'm using process daemon:
WSGIScriptAlias /site1 /site1/wsgi.py
WSGIDaemonProcess site1_proc python-path=S:/Site_1/VirtualEnvSite_1/Lib/site-packages python-home="c:/users/mmyuser/appdata/local/programs/python/python36"
WSGIProcessGroup site1_proc
In my case it's still not working for some other reason. Which I haven't identified yet. Individual applications run correctly using reverse proxy. But when I activate both, one of them gives the error: AH00128: File does not exist: /var/www/html/myapp2/. Configuration files are identical.
Here are my config for setting up multiple projects apache | windows | wsgi
httpd.conf
LoadFile "c:/python37/python37.dll"
LoadModule wsgi_module "c:/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/python37"
# site 1 config
WSGIScriptAlias /site1 "C:/Payslips/payslips_app/wsgi.py" application-group=site1
<Directory "C:/Payslips/payslips_app/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/Payslips/static/"
<Directory "C:/Payslips/static/">
Require all granted
</Directory>
# site 2 config
WSGIScriptAlias /site2 "C:/Subsistance-Payments-System/subsistance_payment/wsgi.py" application-group=site2
<Directory "C:/Subsistance-Payments-System/subsistance_payment/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
site1 wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('C:/Payslips/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'payslips_app.settings'
application = get_wsgi_application()
site2 wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('C:/Subsistance-Payments-System/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'subsistance_payment.settings'
application = get_wsgi_application()

Move Django 1.11 project to wsgi

Please help, I could find error.
I'm using django 1.11 and apache (on centos)
There is my wsgi.py
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
activate_this = os.path.expanduser("/var/project/project_python35_venv/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
my django.conf (of httpd)
WSGILazyInitialization On
WSGIRestrictEmbedded On
WSGIPassAuthorization On
WSGIDaemonProcess project user=apache group=apache processes=10 threads=10 maximum-requests=10000 python-path=/var/project/project_python35_venv/lib/python3.5/site-packages python-home=/var/project/project_python35_venv/lib/python3.5
#WSGIProcessGroup project
#WSGIApplicationGroup %{GLOBAL}
#WSGIPythonHome /var/project/project_python35_venv/lib/python3.5
<VirtualHost *:80>
<Directory /var/project/project_python35_venv>
Require all granted
</Directory>
CustomLog /var/log/httpd/project-access.log common
ErrorLog /var/log/httpd/project-error.log
DocumentRoot /var/project/project/project/
WSGIScriptAlias / /var/project/project/project/wsgi.py
Alias /static /var/project/project/project/static/
<Directory /var/project/project/project/static>
Require all granted
</Directory>
<Directory /var/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
I'm trying all cases, but still got this error on my log of httpd :
ImportError: No module named site
Thank you all for the help
Try this
wsgi
import os
import sys
PROJECT_DIR = '/var/project'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
def execfile(filename):
globals = dict( __file__ = filename )
exec( open(filename).read(), globals )
activate_this = os.path.join( PROJECT_DIR, 'project_python35_venv/bin', 'activate_this.py' )
execfile( activate_this )
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
and apache.conf
WSGILazyInitialization On
WSGIRestrictEmbedded On
WSGIPassAuthorization On
WSGIDaemonProcess project python-path=/var/project/project/:/var/project_python35_venv/lib/python3.5/site-packages/
WSGIProcessGroup project
<VirtualHost *:80>
<Directory /var/project/project_python35_venv>
Require all granted
</Directory>
CustomLog /var/log/httpd/project-access.log common
ErrorLog /var/log/httpd/project-error.log
DocumentRoot /var/project/project/
WSGIScriptAlias / /var/project/project/wsgi.py
Alias /var/project/project/static /var/project/project/static/
<Directory /var/project/project/static>
Require all granted
</Directory>
<Directory /var/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>

Deploying Flask app on a vps (Apache/Debian)

I'm trying to deploy a Flask app on a vps which OS is Debian and which is using Apache. I'm completely new to Apache so my problem may look simple but yet I was not able to find any solution on the web (I read a couple of tutorials and searched in this forum).
The server is running fine (it is already used for other purposes). When I try to access my app with www.myservername/web_app I get a 404 Not Found Error. Following http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/, here is what I've done:
I placed my application in /var/www/web_app/. In /var/www/web_app/app/init.py I created an instance of my app (named app) and configured it.
I placed the following .wsgi file in /var/www/web_app/:
activate_this = '/var/www/web_app/.pyenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this)
import sys
from app import app as application
Here is the /etc/apache2/sites-available/000-default.conf file (the site is enabled) :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory /var/www/html/redmine>
RailsBaseURI /redmine
PassengerResolveSymlinksInDocumentRoot on
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess app user=www-data group=www-data threads=5
WSGIScriptAlias /web_app /var/www/web_app/app.wsgi
<Directory /var/www/web_app>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I also tried to replace /web_app with /var/www/web_app in the WSGIScriptAlias and also to access myservername/var/www/web_app. Moreover I tried to comment out the Rails/Passenger directives in the first Directory tag.
Of course I installed the wsgi module. I restarted the server before trying to access the page. Here is the access log:
... "GET /web_app HTTP/1.1" 404 508
And the error log :
[error] ... File does not exist : /var/www/web_app
Finally, my flask app - when using flask development server - works fine.
Thanks for your help!

How can I run django using apache2?

I'm trying to run django on apache2 using mod_wsgi, but when I'm trying to connect "locatoka.ru" I get "Forbidden You don't have permission to access / on this server."
My actions:
I added to httpd.conf
LoadModule wsgi_module /usr/local/Cellar/mod_wsgi/3.2/libexec/mod_wsgi.so
changed httpd.conf
WSGIScriptAlias / /Users/Loginov/Desktop/project/project/wsgi.py
<VirtualHost locatoka.ru:80>
ServerName locatoka.ru
ServerAlias www.locatoka.ru
DocumentRoot "/Users/Loginov/Desktop/project"
<Directory /Users/Loginov/Desktop/project/project>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
</VirtualHost>
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
I'm using Mac OS X El Capitan and Python3.

Unstable loading time when using mod_wsgi on Windows

My system has following version of software installed:
httpd 2.4.16 win64
Python 3.4.3 amd64
mod_wsgi 4.4.13 ap24vc10 cp34 none win amd64
I have created two environment using virtualenv for two Django projects(just default It worked! page) one hosted on one.local.com(VirtualHost) and other on two.local.com(VirtualHost). Below code is the VirtualHost configuration for Apache's httpd-vhost.conf file.
<VirtualHost *:80>
WSGIApplicationGroup %{ENV:ONE_GROUP}
ServerName one.local.com
ServerAdmin admin#example.com
ErrorLog "D:/_pythonDev/Projects/logs/one.local.com-error.log"
CustomLog "D:/_pythonDev/Projects/logs/one.local.com-access.log" common
WSGIScriptAlias / "D:/_pythonDev/Projects/Project1/Project1/wsgi.py" application-group=%{ENV:ONE_GROUP}
# I also tried WSGIImportScript
<Directory "D:/_pythonDev/Projects/Project1/Project1">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /favicon.ico "D:/_pythonDev/Projects/Project1/static/favicon.ico"
Alias /static/ "D:/_pythonDev/Projects/Project1/static/"
<Directory "D:/_pythonDev/Projects/Project1/static">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
WSGIApplicationGroup %{ENV:TWO_GROUP}
ServerName two.local.com
ServerAdmin admin#example.com
ErrorLog "D:/_pythonDev/Projects/logs/two.local.com-error.log"
CustomLog "D:/_pythonDev/Projects/logs/two.local.com-access.log" common
WSGIScriptAlias / "D:/_pythonDev/Projects/Project2/Project2/wsgi.py" application-group=%{ENV:TWO_GROUP}
<Directory "D:/_pythonDev/Projects/Project2/Project2">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /favicon.ico "D:/_pythonDev/Projects/Project2/static/favicon.ico"
Alias /static/ "D:/_pythonDev/Projects/Project2/static/"
<Directory "D:/_pythonDev/Projects/Project2/static">
Require all granted
</Directory>
</VirtualHost>
Following is the wsgi.py for one.local.com
import os
import sys
import site
site.addsitedir("D:/_pythonDev/env/env1/Lib/site-packages")
sys.path.append("D:/_pythonDev/Projects/Project1/Project1")
sys.path.append("D:/_pythonDev/Projects/Project1")
activate_env_file = "D:/_pythonDev/env/env1/Scripts/activate_this.py"
exec(open(activate_env_file).read(), dict(__file__=activate_env_file))
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "Project1.settings"
application = get_wsgi_application()
Problem:
Loading time is unstable it takes about 10s.
Answer required:
Reason of unstable loading time.
Answer to solve it.

Categories

Resources