apache + mod_wsgi + django +askbot - django

error:File does not exist:
/home/WorkSpace/fenxiang/site_media/media/photos/3.jpg the real
address 3.jpg is at
/home/WorkSpace/fenxiang/askbot/upfiles/photos/3.jpg
All apalication is run well as python manage.py runserver:
centos6.2 python2.7(/opt/python2.7.2)
hpptd.conf
<VirtualHost *:80>
ServerAdmin matt#360yuer.com
ServerName www.360yuer.com
DocumentRoot /home/WorkSpace/fenxiang
WSGIScriptAlias / /home/WorkSpace/fenxiang/apache/fenxiang.wsgi
Alias /site_media/ /home/WorkSpace/fenxiang/site_media/
Alias /upfiles/ /home/WorkSpace/fenxiang/askbot/upfiles/
Alias /static/ /home/WorkSpace/fenxiang/static/
AddType text/html .py
<Directory /home/WorkSpace/fenxiang/apache >
Order allow,deny
Allow from all
</Directory>
<Directory /home/WorkSpace/fenxiang/site_media>
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
<Directory /home/WorkSpace/fenxiang/askbot/upfiles>
Order deny,allow
Allow from all
</Directory>
<Directory /home/WorkSpace/fenxiang/static>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
I am a newer, and I do not know how to fix it ,
the current problem is can not find the /askbot/upfiles/3.jpg, and some css in /static/css
settings.py
STATICFILES_DIRS = (os.path.join(ASKBOT_ROOT, 'skins'), os.path.join(PROJECT_ROOT, "static"), ASKBOT_EXTRA_SKINS_DIR)
RECAPTCHA_USE_SSL = True

Instead of:
/askbot/upfiles/3.jpg
you should be using URL with:
/upfiles/3.jpg
in it. That is what you have Alias set up for.
As for CSS files, are they actually in the directory:
/home/WorkSpace/fenxiang/static/css/

Related

What am I missing here? Apache keeps serving default page

I have configured my Django site but Apache keeps serving the default apache's page. What am I missing here? My setup is Django 1.10 on CentOS server with python3.5.
Project structure
/home/sbsadmin/web/sbsportal
requirements.txt
src
manage.py
media
sbsportal
__init__.py
__pycache__
settings.py
urls.py
wsgi.py
static
templates
venv
/etc/httpd/conf.d/sbsportal.conf
LoadModule wsgi_module modules/mod_wsgi.so
<VirtualHost *:80>
ServerAdmin admin#email.com
ServerName sbsportal
ServerAlias sbsportal.com
DocumentRoot /home/sbsadmin/web/sbsportal/src/
WSGIDaemonProcess sbsportal python-path=/home/sbsadmin/web/sbsportal/src:/home/sbsadmin/web/sbsportal/venv/lib/python3.5/site-packages
WSGIApplicationGroup sbsportal
WSGIScriptAlias / /home/sbsadmin/web/sbsportal/src/sbsportal/wsgi.py process-group=djangoproj
<Directory /home/sbsadmin/web/sbsportal/src>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Order allow,deny
Require all granted
</Directory>
<Directory /home/sbsadmin/web/sbsportal/src/sbsportal>
<Files wsgi.py>
Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
Alias /static /home/sbsadmin/web/sbsportal/src/static
<Directory /home/sbsadmin/web/sbsportal/src/static>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Order allow,deny
Require all granted
</Directory>
Alias /static /home/sbsadmin/web/sbsportal/src/templates
<Directory /home/sbsadmin/web/sbsportal/src/templates>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Order allow,deny
Require all granted
</Directory>
Alias /media /home/sbsadmin/web/sbsportal/src/media
<Directory /home/sbsadmin/web/sbsportal/src/media>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Order allow,deny
Require all granted
</Directory>
</VirtualHost>
wsgi.py
"""
WSGI config for sbsportal project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sbsportal.settings")
application = get_wsgi_application()
Settings.py
.
.
.
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
.
.
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
I have resolved pretty much all the problems. Only thin is that now I am seeing 403 forbidden error.
Did you added selinux context in your project diretory ? if not do the following :
semanage fcontext -a -t httpd_sys_content_t '/home/sbsadmin/myproject/(/.*)'
restorecon -Rv /home/sbsadmin/myproject/
Or try disabling selinux setenforce 0

Django 1.8 App shows folder strucutre when added SSL

My site is working on http
I now want it to work using a SSl certificate. I've generated the keys and set up the virtualhost:
<VirtualHost *:80>
WSGIDaemonProcess pms python-path=/home/ubuntu/myapp/myapp:/home/ubuntu/myapp/env/lib/python3.4$
WSGIProcessGroup myapp
WSGIScriptAlias / /home/ubuntu/myapp/myapp/myapp/wsgi.py
<Directory /home/ubuntu/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerAdmin support#myapp.com
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
ServerName leanhotelsystem.com
ServerAlias *.leanhotelsystem.com
DocumentRoot /home/ubuntu/myapp/myapp/myapp
<Directory /home/ubuntu/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin support#myapp.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I've also set in wsgi.py:
os.environ['HTTPS'] = "on"
and in settings.py:
WSGI_APPLICATION = 'myapp.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
The problem is that when i access the url with https it shows my folder structure, instead of rendering the homepage.
If I access via http it works fine.
Thanks!
Looks like you forget your WSGI settings section in your new VirtualHost.

Django to pass through some urls to base apache

Is there a way for Django to pass through some urls to whatever apache would resolve them too?
For instance, if I type in: http://< my-ip >. Is there a way to have django just serve up whatever is in /var/www/html/index.html?
Similarly, if I type in http://< my-ip >/devel, is there a way to make django simply serve what's in /var/www/html/devel/?
Basically, I want some urls to "not be touched".
Thanks!
Edit
Following Anentropic's comment, I'd like Apache to call Django only if it can't match the url. How would I need to change httpd.conf to do that? Let's say I want Django to respond to only /polls/, /admin/ and /accounts/.
Here's the relevant portion from my httpd conf file:
<VirtualHost *:80>
#DocumentRoot /home/ec2-user/srv/mysite
DocumentRoot /var/www/html/
ServerName <My IP ADDRESS>
WSGIScriptAlias / /home/ec2-user/srv/mysite/apache/wsgi.py
# Alias /phpmyadmin /var/www/html/phpmyadmin
# <Location /phpmyadmin>
# SetHandler None
# </Location>
<Directory /home/ec2-user/srv/mysite/media>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ec2-user/srv/mysite/apache>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
Alias /media/ /home/ec2-user/srv/mysite/media/
Alias /static/ /home/ec2-user/srv/mysite/static/
<Directory /home/ec2-user/srv/mysite/static>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
If you'd like to serve static html pages you could use the flatpages app.
Again if you'd like to use different languages (php etc) I believe that you'd have to set up different virtual host in you apache config file to catch the url before it gets served to Django and redirect it to the correct folder. i.e:
<VirtualHost *:80>
ServerName staging.mydomain.com
DocumentRoot /var/www/html/mydomain.com/staging/
</VirtualHost>
<VirtualHost *:80>
ServerName dev.mydomain.com
DocumentRoot /var/www/html/mydomain.com/dev/
</VirtualHost>
EDIT
<VirtualHost *:80>
#DocumentRoot /home/ec2-user/srv/mysite
DocumentRoot /var/www/html/
ServerName <My IP ADDRESS>
Alias /phpmyadmin /var/www/html/phpmyadmin
<Location /phpmyadmin>
SetHandler None
</Location>
<Directory /home/ec2-user/srv/mysite/media>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ec2-user/srv/mysite/apache>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
WSGIScriptAlias /polls /home/ec2-user/srv/mysite/apache/wsgi.py
WSGIScriptAlias /admin /home/ec2-user/srv/mysite/apache/wsgi.py
WSGIScriptAlias /accounts /home/ec2-user/srv/mysite/apache/wsgi.py
Alias /media/ /home/ec2-user/srv/mysite/media/
Alias /static/ /home/ec2-user/srv/mysite/static/
<Directory /home/ec2-user/srv/mysite/static>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

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?

problem using WSGIApplicationGroup %{GLOBAL} in apache configuration

im using django with apache and mod_wsgi
i am facing a problem when i use WSGIApplicationGroup %{GLOBAL} in apache configuration file (.conf) . i dont know if i am using this directive correctly or i need to use it in another way , the problem is that i needed to add this directive to fix a problem for xapian as described in this ticket (http://trac.xapian.org/ticket/185) after that the search started to work but all my sites contents got mixed up, meaning site1 content appears on site2.when i removed WSGIApplicationGroup %{GLOBAL} , sites are rendering properly again but search stopped working.
here is my .conf file contents:
NameVirtualHost my_ip_address:80
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site1.com
ServerAlias site1
WSGIScriptAlias / "/home/sa/www/site1/apache/django.wsgi"
<Directory "/home/sa/www/site1/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site1/media/"
<Directory "/home/sa/www/site1/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site2.com
ServerAlias site2
WSGIScriptAlias / "/home/sa/www/site2/apache/django.wsgi"
<Directory "/home/sa/www/site2/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site2/media/"
<Directory "/home/sa/www/site2/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
< VirtualHost my_ip_address:80 >
ServerName www.site3.com
ServerAlias site3
WSGIScriptAlias / "/home/sa/www/site3/apache/django.wsgi"
<Directory "/home/sa/www/site3/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site3/media/"
<Directory "/home/sa/www/site3/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site4.com
ServerAlias site4
WSGIScriptAlias / "/home/sa/www/site4/apache/django.wsgi"
<Directory "/home/sa/www/site4/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site4/media/"
<Directory "/home/sa/www/site4/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
WSGIApplicationGroup %{GLOBAL}
<VirtualHost my_ip_address:80>
ServerName www.site5.com
ServerAlias site5
WSGIScriptAlias / "/home/sa/www/site5/apache/django.wsgi"
<Directory "/home/sa/www/site5/apache">
Allow from all
</Directory>
Alias /site_media/ "/home/sa/www/site5/media/"
<Directory "/home/sa/www/site5/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/"
<Directory "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/">
Order allow,deny
Options Indexes FollowSymLinks
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
has anybody faced this issue
any suggestions
thanks
Django's implementation prevents multiple Django instances running in same interpreter (application group). Thus if running multiple Django sites on same Apache server and must set WSGIApplicationGroup to %{GLOBAL}, then you MUST use daemon mode and delegate each Django site to a separate daemon process group. Daemon mode is preferred anyway.
Ensure you read:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
The latter explaining part why daemon mode is good as far as making code reloading easier.