17👍
The second directory block doesn’t match where you have your WSGI script file installed. It is very bad practice though to stick the WSGI script file in a location where source code or other sensitive files exist, ie., same directory or sub directory. Instead you should stick it in a sub directory of its own. Thus:
WSGIScriptAlias / /home/wong2/Code/python/django2/atest/apache/setting.wsgi
<Directory "/home/wong2/Code/python/django2/atest/apache">
Order allow,deny
Allow from all
</Directory>
So, create ‘apache’ subdirectory under ‘atest’. Move ‘setting.wsgi’ into that ‘apache’ subdirectory and change config to above.
Your problem also may be caused by restrictive permisions on your home directory as Apache cannot see inside.
Go watch:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
as it explains these permissions problems as well as issues like where to stick your code and the WSGI script file.
Also read:
10👍
With Django 1.5+ you should use the suggested way described in the documentation:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/
- Error Map Keys Must be unique while using YAML extension field in docker compose for django application
- Django ListView customising queryset
- Change default Django REST Framework home page title
- Python and sqlite3 – importing and exporting databases
6👍
I had the same problem due to restricted file permissions.
By default your home folder user has the settings:
ls -l /home/
drwx—— 36 user user 12288 Nov 28 20:56 user
meaning that no one else but yourself is able to even browse that folder.
Adding execute option to the folder fixed my problem
chmod o+x /home/user/
ls -l /home/
drwx—–x 36 user user 12288 Nov 28 20:56 user
0👍
try http://localhost/index.html does that show the apache page?
If you wsgi is configured on root correctly it wont.
You get that error message because you might be asking the webserver for the directory listing of www folder
edit:
My projects are always in
/var/pyproj//pysrc/
and server files i put in
/var/py_proj//server/
Here is my go to wsgi script
import os, sys
import logging
logger =logging.getLogger("")
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)-8s %(messages)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
sys.stdout = sys.stderr
from os.path import abspath, dirname, join
import site
PROJECT_ROOT = abspath(join(dirname(__file__), "../pysrc"))
SETTINGS_LOC = abspath(join(PROJECT_ROOT, ''))
site.addsitedir(SETTINGS_LOC)
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
from django.core.management import setup_environ
import settings
setup_environ(settings)
sys.path.insert(0, join(PROJECT_ROOT, "apps"))
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
and i use a vhost.conf
WSGIDaemonProcess pinax_demo user=www-data group=www-data threads=10 python-path=/var/.virtualenvs/pinax_demo/lib/python2.6/site-packages
<Directory /var/py_proj/pinax_demo/server/>
Order deny,allow
Allow from all
</Directory>
Alias /pinax_demo /var/py_proj/pinax_demo/server/pinax_demo.wsgi
<Location /pinax_demo/>
#WSGIProcessGroup must match the WSGIDaemonProcess
WSGIProcessGroup pinax_demo
SetHandler wsgi-script
Options +ExecCGI
</Location>
which i include in the sites-available folder in a file that looks like this
<VirtualHost *:8080>
DocumentRoot /var/www/
<Directory /var/www/>
Order deny,allow
Allow from all
Options -Indexes FollowSymLinks
DirectoryIndex index.php
AllowOverride None
</Directory>
ServerAdmin oto@example.com
LogLevel error
ErrorLog /var/srv_logs/apache_error.log
CustomLog /var/srv_logs/apache_access.log combined
#insert
Include /var/py_proj/pinax_demo/server/vhost.conf
Include /var/py_proj/<other>/server/vhost.conf
Include /var/py_proj/<other>/server/vhost.conf
</VirtualHost>
httpd.conf is empty. Apache is also terrible at sending static files so i have my apache setup on port 8080 and nginx setup on port 80 which forwards to apache. You should be able to just change the port on my sites-avaiable file to run it without nginx but i would not go live that way
- Django Rest Ordering custom
- Django queryset filter GT, LT, GTE, LTE returns full object list
- TypeError: __call__() missing 1 required positional argument: 'send' Django
- Django 1.9 JSONField order_by
- Very simple user input in django
-1👍
You may get a surprise where your WSGI has its home directory! On my admittedly naive wsgi_mod installation, it is / – I was so surprised I had to write this script to make sure:
import os
def application(environ, start_response):
status = '200 OK'; e=os.listdir(os.getcwd())
output = '''WSGI %s<hr>'''%(e)
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
That means imported applications will need a full path to be found, e.g.:
sys.path.append('/home/foo/www/Forms')
from DataCommon import page
This is the recommended (by Google) approach to this:
import sys; path='/home/foo/www/Forms';
if path not in sys.path: sys.path.append(path)