Django/Mod_WSGI 'client denied by server configuration' - django

I'm attempting to set up Apache 2.2, Django 1.1.2 and Gentoo. I wish to serve my project with the address: /comics
I followed the mod_wsgi directions in the django documentation to the letter, coming up with these files:
/etc/apache2/modules.d/70_mod_wsgi.conf
<IfDefine WSGI>
LoadModule wsgi_module modules/mod_wsgi.so
</IfDefine>
WSGIScriptAlias /comics /home/****/django/comicky/apache/django.wsgi
and
/home/****/django/comicky/apache/django.wsgi
import os
import sys
sys.path.append('/home/****/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'comicky.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
However, when I attempt to load the page, I get this in /var/log/apache2/error_log:
client denied by server configuration: /home/****/django/comicky/apache/django.wsgi
Any ideas?

Sounds like a permissions issue from your conf file. See, for example:
Apache Error: Client denied by server configuration

Make sure your conf file matches this: conf sample file. I had to add the wsgi.py at the end to make mine work

Related

Django wsgi.py + Apache can't deploy, but

Environment and version: Windows 8-64bit, Wamp Apache 2.4.9, Python 3.4.2, Django 1.8
Deploying Django with apache using wsgi.py
followed following post got mod_wsgi setup
WSGIScriptAlias /mysite/mysite/wsgi "C:/wamp/www/mysite/mysite/wsgi.py"
WSGIPythonPath "C:/wamp/www/mysite/mysite/"
<Directory "C:/wamp/www/mysite/mysite/">
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Directory:
wamp
|
www
|
testweb1
manage.py
|
testweb1 - settings.py
- urls.py
- wsgi.py
Inside wsgi.py(original code):
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testweb1.settings")
application = get_wsgi_application()
The problem is when starting Wamp Apache server, the icon appear green.
Server Online
But when I enter my ip address and port, for example 125.138.0.1:8080
The page only gives me this:
Apache/2.4.9 (Win64) mod_wsgi/4.4.2 Python/3.4.2 PHP/5.5.12 Server at 125.138.0.1 Port 8080
I had done so many research and followed the doc from
https://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
tried many ways in wsgi.py , still couldn't get let Apache the deploy Django site from home IP address
By the way, in Apache httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Also tried
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
Your WSGIScriptAlias setting is wrong. The first argument should be the path you want your application served at, which is usually the root. So:
WSGIScriptAlias / "C:/wamp/www/mysite/mysite/wsgi.py"

django production server: root path

I am developing a django application. On the development server, everything works just fine.
On the production server (using apache), nothing is working.
1/ I have the error TemplateDoesNotExist at /.
In my settings.py file:
SITE_ROOT = os.path.abspath(os.path.dirname(__name__)). This is the project root path.
templateDir = os.path.join(SITE_ROOT, 'templates/')
TEMPLATE_DIRS = (
templateDir
)
This is the templates path.
2/ If I change SITE_ROOT with the absolute path of the project:
SITE_ROOT="/var/www/europolix"
Templates seem to be recognize but I have another mistake:
No module named getEurlexIdsFunctions
Here is the code:
import sys
sys.path.append('import')
import getEurlexIdsFunctions as eurlexIds
I think that once again the problem comes from a relative path. Apache seems to search 'import' in "var/www/" and not in "var/www/europolix/". Am I right?
Here is my apache configuration:
WSGIScriptAlias /europolix /var/www/europolix/europolix/wsgi.py
WSGIPythonPath /var/www/europolix/
<Directory /var/www/europolix/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Is it a problem of root path not recognized, or is there another problem?
Many thanks.
Well, a couple of things. When working with settings.py is better to declare all the paths as absolute paths. I see in your code that you have this line
SITE_ROOT = os.path.abspath(os.path.dirname(__name__))
for site's root but I think is better if you use __file__ global variable instead of __name__. Like this:
SITE_ROOT = os.path.abspath(os.path.dirname(__file__))
I have a django app in production server and all I had to add to my httpd.conf about wsgi was the load_module directive and this line inside the virtual host
WSGIScriptAlias / C:/Users/ike/Documents/Work/Sincronoz/code/apache/django.wsgi
specifying the alias to the django.wsgi script as the root.
Then in django.wsgi script I have this code:
import os, sys
sys.path.append(r'<full site root to where is settings.py>')
os.environ['DJANGO_SETTINGS_MODULE'] = 'my_project_module.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I think you're better off working with absolute paths and when you got it all working then try to accommodate it for your needs with maybe relative path if you have to.
Hope it helps.
in django project in file wsgi.py i add this 3 lines
import sys
DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)),'..')
sys.path.append(DJANGO_PATH)

Error: Target WSGI script not found or unable to stat when run django on apache

i have a problem when run django on apache:
htdocs/blog/apps/homepage/urls.py:
url(r'^$', 'index', name="h_index"),
url(r'^about/$', 'about', name="h_about"),
url(r'^contact/$', 'contact', name="h_contact"),
url(r'^archive/$', 'archive', name="h_archive"),
htdocs/blog/urls.py
(r'^', include('apps.homepage.urls')),
django.wsgi:
import os
import os.path
import sys
sys.path.append('D:/Coding/xampp/htdocs')
sys.path.append('D:/Coding/xampp/htdocs/blog')
os.environ['DJANGO_SETTINGS_MODULE'] = 'blog.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
httpd.conf:
Alias /static/ "D:/Coding/xampp/htdocs/blog/static/"
WSGIScriptAlias /blog/ "D:/Coding/xampp/htdocs/blog/django.wsgi"
when i run "localhost/blog", it's working. But run "localhost/blog/about/" or other, it's error:
[error] [client ::1] Target WSGI script not found or unable to stat: .../htdocs/blog/django.wsgiabout, referer: http://localhost/blog/
Please notice how your apache configuration doesn't match the documented syntax for mod_wsgi's WSGIScriptAlias.
WSGIScriptAlias /blog/ "D:/Coding/xampp/htdocs/blog/django.wsgi"
should be:
WSGIScriptAlias /blog "D:/Coding/xampp/htdocs/blog/django.wsgi"
(notice no trailing slash after the 2nd token, "/blog")
I just resolved the same issue just now and found this thread Googling. Hope this helps you and future users.
For more information:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines
I would suspect you are not loading the wsgi module. If you look closely at your error message Apache is treating it like a file and adding about to the name of the wsgi script file it looks for - thus it doesn't find it.

Apache Django "client denied by server configuration" error

I found a similar question here, but didn't help me.
I basically have apache setup on my OS X. I also have Django installed.
However, when i try to load the page through the browser locally, i get:
Forbidden
You don't have permission to access / on this server.
I have an original httpd.conf with the only modification of enabling vhosts in which I have:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/Dropbox/project/www/"
ServerName touch.loc
# ServerAlias www.dummy-host.example.com
ErrorLog "/Dropbox/project/www/log/error.log"
CustomLog "/Dropbox/project/www/log/access.log" common
</VirtualHost>
And the error.log file gives:
[Tue May 03 20:22:56 2011] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /Dropbox/project/www/
I read around and it looks like i have to add the following to the httpd.conf:
<Directory /Dropbox/project/www >
Order deny,allow
Allow from all
</Directory>
In which case i get:
[Tue May 03 20:27:55 2011] [error] [client 127.0.0.1] client denied by server configuration: /Dropbox/project/www/
Can someone help me fix this annoyance? How can I further Investigate it?
Does it have to do with users/groups?
UPDATE:
I then added the Options +Indexes and the permissions opened. However when i try to load the page, file structure appears instead of the wsgi file to pickup and load the website. What would be the reason for that?
here is my .wsgi file:
import os
import sys
sys.stdout = sys.stderr
# Add the virtual Python environment site-packages directory to the path
import site
site.addsitedir('/usr/lib/python2.6/dist-packages')
#If your project is not on your PYTHONPATH by default you can add the following
sys.path.append('/Dropbox/project/www/')
sys.path.append('/Dropbox/project/www/project')
# Avoid ``[Errno 13] Permission denied: '/var/www/.python-eggs'`` messages
os.environ['PYTHON_EGG_CACHE'] = '/Dropbox/project/www/mod_wsgi/egg-cache'
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
You seem to be missing anything in your Apache configuration that actually serves the Django application. You need to read the Django mod_wsgi documentation - the first line of code there is what you're missing.
Note that your code should not live under the DocumentRoot.
The problem I see is in Dropbox folder
I have made so:
chmod o+x /home/your_name/Dropbox
That resolves permissions

Django set up with WSGI in directory below the domain root: Url problems in templates

Django has been up and running on my mod_wsgi implementation of Apache (on Windows 7 x64, btw) for a bit. This was a huge pain, complete with having to actually hand-modify registry values to get things to install correctly and to get Django to use the same MySQL install as all my other apps. I also had to modify the PATH variable by double-escaping parentheses (Program Files (x86)) because they were screwing with batch files. But this is mostly Microsoft's fault and I'm rambling.
Here is my issue:
All of the URLs used in the URLCONF and in views work correctly. The only thing which doesn't is in templates when I try to work off the site root URL. I am running a development server and I have two Django sites, this particular one running off of www.example.com/testing.
In the templates, if I just put "/" in an < a >, then it will point to www.example.com/, and NOT www.example.com/testing/. I have read a topic on this but the issue wasn't resolved because the poster was being stubborn. I am posting my WSGI configuration in the httpd.conf below:
Listen 127.0.0.1:8001
VirtualHost *:8001 >
ServerName ****.net/testing
ServerAdmin *******#gmail.com
ErrorLog ********.log
WSGIScriptAlias /testing ****/htdocs/testing/apache/django.wsgi
Directory ****/htdocs/testing/apache >
Order deny,allow
Allow from all
/Directory>
Location "/media">
SetHandler None
/Location>
/VirtualHost>
Note: all "<" omitted so the tags would show
Here is the file django.wsgi in the above directory:
import sys
import os
sys.path.insert(0, '*****/Django/')
sys.path.insert(0, '*****/htdocs/')
sys.path.insert(0, '*****/htdocs/testing')
sys.path.insert(0, '*****/htdocs/testing/apache')
os.environ['DJANGO_SETTINGS_MODULE'] = 'testing.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
import testing.monitor
testing.monitor.start(interval=1.0)
I have an Nginx frontend which passes any non-static file from testing/ to :8001 for Apache to catch with this virtualhost.
If I omit the root "htdocs/" line from the django.wsgi file, I just get 500 errors on the site. Also, if I use the URL form relative to the current URL (ie "example/" instead of "/example/"), that works alright. But if I add the initial "/" to put the URL off the root, it will make it off of "www.example.com" instead of "www.example.com/testing" like I wanted.
Sorry for the very long post, but I wanted to be as clear as possible. Thank you for your time.
This is why you should not hard-code URLs in your templates. Of course / will take you to the root of the site, not the root of your app - that's what it's supposed to do.
Instead, give your root view a name in your urlconf:
urlpatterns = patterns('',
url('^$', 'myapp.views.index', name='home')
)
now in your template you can do:
Home
and this will correctly resolve to /testing/.