*Using Django 1.5, mod_WSGI 3.3 and Apache 2.2*
The Mod_WSGI module has been successfully installed into Apache.
I have also created a very basic project using django-admin.py called "check"
So now according to the Django Documentation on how to configure mod_wsgi
I have entered the following code into the Apache httpd.conf where it looks like this -
<VirtualHost 192.254.132.95:80>
ServerName bangtestwsgi.mbox140.com
ServerAlias www.bangtestwsgi.mbox140.com
DocumentRoot /home/bangwsgi/public_html
ServerAdmin webmaster#bangtestwsgi.mbox140.com
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/bangtestwsgi.mbox140.com combined
CustomLog /usr/local/apache/domlogs/bangtestwsgi.mbox140.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User bangwsgi # Needed for Cpanel::ApacheConf
UserDir enabled bangwsgi
<IfModule mod_suphp.c>
suPHP_UserGroup bangwsgi bangwsgi
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup bangwsgi bangwsgi
</IfModule>
</IfModule>
WSGIScriptAlias / /home/bangwsgi/check/check/wsgi.py
WSGIPythonPath /home/bangwsgi/check
<Directory /home/bangwsgi/check/check>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
</VirtualHost>
Currently my DNS hasn't propagated so I am using 192.254.132.95/~bangwsgi/ to access the app (as told to me by Hostgator)
The thing is that nothing is happening. There is nothing in the Apache error log. There seems to be sign that the wsgi script is even running. Can someone tell me what I can do differently to make this work?
I'm not sure why you are going to /~bangwsgi/. Your WSGI app is being served at /, as defined by the first parameter to WSGIScriptAlias.
It works on removing the line
WSGIPythonPath /home/bangwsgi/check
And changing Require all granted
to Allow from all
Related
Hi Guys I am trying to route my domain to server 139.5X.X.XXX
Following is My DNS record Details in Hostinger :-
Type Name Priority Content IP-V4 TTL
A www 0 139.5X.X.XXX 600
A # 0 139.5X.X.XXX 14400
Now I am seeing default apache page while browsing the domain (Server serving default apache page (Digital Ocean Ubuntu Droplet)) .
But after configuring a Django service to domain it taking too long to respond and ending up with "This Site can't be Reached"
following is the conf file which I am using
<VirtualHost *:80>
ServerName tellie.in
ServerAlias www.tellie.in
Redirect permanent / https://tellie.in/
RewriteEngine on
RewriteCond %{SERVER_NAME} =tellie.in [OR]
RewriteCond %{SERVER_NAME} =www.tellie.in
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#tellie.in
ServerName tellie.in
ServerAlias www.tellie.in
DocumentRoot /home/srv/telli
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/srv/telli/telli/static
<Directory /home/srv/telli/telli/static>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Alias /media /home/srv/telli/telli/media
<Directory /home/srv/telli/telli/media>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/srv/telli/telli/telli>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess telli python-path=/home/srv/telli/telli python-home=/home/srv/telli/venv
WSGIProcessGroup telli
WSGIScriptAlias / /home/srv/telli/telli/telli/wsgi.py
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/tellie.in/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/tellie.in/privkey.pem
</VirtualHost>
Is there anything wrong that could cause the problem I am facing
Make sure that Apache has rx access to the directories under /home/srv/, It is better to move the code out of HOME and in a general mountpoint as /var or /data
I am trying to run a django application on VPS via apache2, but I get the following in the website-error file, also 400(Bad Request):
Exception ignored in: <function Local.__del__ at 0x7f47273f48b0>
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
I successfully ran a simple website that was made with "django-admin startproject" and could be viewed, but uploading project, made with the following skeleton, produces this error: https://django-project-skeleton.readthedocs.io/en/latest/apache2_vhost.html
I have tried including the python site-packages in the WSGIDaemon and by exluding them it produces the same effect.
In addition to this, I have also added:
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
But again, no change
Because this post was upvoted and maybe it can help the others searching for that problem: this is my website.conf, just change example to your domain name. It also redirects to your https version of the website:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/example/example/wsgi.py
Alias /static/ /var/www/example/run/static/
Alias /media/ /var/www/example/run/media/
WSGIDaemonProcess example python-path=/var/www/example
# PROCESS_GROUP specifies a distinct name for the process group
WSGIProcessGroup example
<Directory /var/www/example/example>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/example/run/static>
Require all granted
</Directory>
<Directory /var/www/example/run/media>
Require all granted
</Directory>
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
SSLEngine on
SSLCertificateFile /var/ssl/example.crt
SSLCertificateKeyFile /var/ssl/example.key
SSLCertificateChainFile /var/ssl/example.ca-bundle
</VirtualHost>
Open your apache configuration's file then add "LogLevel info" inside the tag : VirtualHost at the end (before closing tag). It's works for me
I've encountered the same (ignored) exception in my apache2 error logs while running a functional application. It seems like you're using WSGI, so this ASGI-related python package shouldn't be the cause of your 400 error.
I am trying to create a small django site and use iRedMail for e-mail. I installed iRedMail first, and ensured that it worked. I could go to both www.domain.com/iredadmin and www.domain.com/mail and have it work perfectly. My next step was to install my django site and configure Apache. Unfortunately, this caused my django site to try and handle /mail/ and /iredadmin/. I've been fidgeting with the config for a few hours now and have no idea what to do. Here are the settings:
apache2.conf:
# Defaults...
WSGIPythonPath /path/to/website.com/website
sites-enabled/website.com:
<VirtualHost *:80>
ServerName website.in
ServerAlias www.website.in
ErrorLog ${APACHE_LOG_DIR}/error.log
Alias /static /path/to/website.com/website/static
Alias /media /path/to/website.com/website/media
Alias /mail /usr/share/apache2/roundcubemail/
Alias /admin /usr/share/apache2/iredadmin/
<Directory /usr/share/apache2/roundcubemail/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /path/to/website.com/website/website.wsgi
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE website.settings
PythonDebug Off
PythonPath "['/path/to/website.com/website/']+sys.path"
</Location>
<Directory /path/to/website.com/website>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Directory /path/to/website.com/website/static>
Order allow,deny
Allow from all
</Directory>
<Location /static/>
SetHandler None
</Location>
<Directory /path/to/website.com/website/media>
Order allow,deny
Allow from all
</Directory>
<Location /media/>
SetHandler None
</Location>
</VirtualHost>
The django website displays fine, although I have been getting internal server errors.
You are trying to use both mod_wsgi and mod_python to handle the Django site at the same time, with mod_python overriding mod_wsgi. Choose one of the other. Since mod_python is no longer developed or supported and support for it in Django deprecated, probably not a good option to keep using it.
The next thing which is wrong is:
Alias /mail /usr/share/apache2/roundcubemail/
Alias /admin /usr/share/apache2/iredadmin/
Remove the trailing slashes:
Alias /mail /usr/share/apache2/roundcubemail
Alias /admin /usr/share/apache2/iredadmin
Even then it will still not work, because when using mod_python you have to tell mod_python not to handle those paths.
<Location /mail/>
SetHandler None
</Location>
<Location /admin/>
SetHandler None
</Location>
A further problem you may have is that /admin is usually used for the Django admin interface and you are overriding that.
I am using a django based framework and have successfully figured Apache settings for http mode. Basically I have done the setting correctly on <VirtualHost *:80> ... </VirtualHost> and when I do, http://mysite.domain.com I get routed correctly to my site and the site pages and the skins get render correctly.
I have setup https://mysite.domain.com to work with shibboleth, shibboleth is working and when use the https I get routed to login credential page via shibboleth server, and after successful login I get redirect to https://mysite.domain.com but site doesn't get rendered correctly and skins don't show up as same as http://mysite.domain.com.
Here is my Apache settings, I am trying to understand what I am doing wrong here
<VirtualHost *:443>
ServerAdmin myname#mydomain.com
DocumentRoot /code/vEnviornment/mysite
ServerName mydomain.com
#<LocationMatch "^(?!/admin)">
#<LocationMatch "^(?!/m)">
# RewriteEngine on
# RewriteRule django.wsgi(.*)$ https://mydomain.com:443$1 [L,R=301]
#</LocationMatch>
SSLEngine on
#your SSL keys
#I have removed this wasn't comfortable putting SSL key info
#Alias /admin/media/ /usr/local/lib/python2.6/site-packages/django/contrib/admin/media/
Alias /admin/media/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/
WSGIScriptAlias /m/ /code/vEnviornment/mysite/django.wsgi
<Directory "/">
AuthType shibboleth
ShibRequestSetting requireSession 1
Require valid-user
</Directory>
Alias /Shibboleth.sso /tmp
# CustomLog /var/log/httpd/mysite/access_log common
# ErrorLog /var/log/httpd/mysite/error_log
CustomLog /var/log/apache2/mysite/access_log common
ErrorLog /var/log/apache2/mysite/error_log
</VirtualHost>
And here is how I have hetup http:
<VirtualHost *:80>
ServerAdmin myname#mydomain.com
DocumentRoot /code/vEnviornment/mysite
ServerName mysite.mydomain.com
#aliases to serve static media directly
#will probably need adjustment
Alias /m/ /code/vEnviornment/mysite/static/
Alias /upfiles/ /code/vEnviornment/mysite/myframework/upfiles/
<DirectoryMatch "/code/vEnviornment/mysite/myframework/skins/([^/]+)/media">
Order deny,allow
Allow from all
</DirectoryMatch>
<Directory "/code/vEnviornment/mysite/myframework/upfiles">
Order deny,allow
Allow from all
</Directory>
#must be a distinct name within your apache configuration
WSGIDaemonProcess mysite2
WSGIProcessGroup mysite2
WSGIScriptAlias / /code/vEnviornment/mysite/django.wsgi
#make all admin stuff except media go through secure connection
<LocationMatch "/admin(?!/media)">
RewriteEngine on
RewriteRule /admin(.*)$ https://128.101.35.71/admin$1 [L,R=301]
</LocationMatch>
# CustomLog /var/log/httpd/mysite/access_log common
# ErrorLog /var/log/httpd/mysite/error_log
CustomLog /var/log/apache2/mysite/access_log common
ErrorLog /var/log/apache2/mysite/error_log
LogLevel debug
</VirtualHost>
What am I doing wrong here to render the site incorrectly via https?
Alias /m/ /code/vEnviornment/mysite/static/
Alias /upfiles/ /code/vEnviornment/mysite/myframework/upfiles/
These two lines are missing in https virual host
and
your WSGIScriptAlias should point to / not /m/
Is it possible to deploy a Django app on Apache + mod_wsgi (the standard way) but with HTTP authentication in front of the whole thing?
Basically, I need an extra layer of HTTP security before any user, Django-authenticated or anonymous, is even able to reach the app.
Is this possible? If so, where do the Apache auth directives go?
Yes, it's possible.
With mod_wsgi on /, any resources to be provided by apache need to be listed as aliases.
Auth directives and host restrictions live in Location directives.
So I've disabled any apache access restrictions on things like css, and provided host/ip based access to another directory.
<VirtualHost *:80>
Servername app.domain.example
CustomLog logs/access_log combined
ErrorLog logs/error_log
DocumentRoot "/home/app/apache/app/html"
Alias /media/ /home/app/apache/app/html/media/
<Location />
Options None
AuthType Basic
AuthName "Login Prompt"
AuthUserFile /path/to/passwd.file
Require valid-user
</Location>
<Location /media>
Order allow,deny
Allow from all
Satisfy any
</Location>
WSGIDaemonProcess app user=app group=app processes=5 threads=1 display-name=app_WSGI
WSGIProcessGroup app
WSGIScriptAlias / /home/app/apache/app.wsgi
</VirtualHost>
Sure, here is example from one site:
<VirtualHost *:80>
ServerName djangoproject.domain.biz
DocumentRoot "/home/user/websites/djangoproject/website/"
WSGIDaemonProcess djangoproject python-path=/home/user/.virtualenvs/djangoproject/lib/python2
.6/site-packages/ user=user group=user threads=1
WSGIProcessGroup djangoproject
WSGIScriptAlias / /home/user/websites/djangoproject/website/django.wsgi
<Directory "/home/user/websites/djangoproject/website/">
Order deny,allow
Allow from all
AuthType Basic
AuthName "By Invitation Only"
AuthUserFile /etc/apache2/passwords
Require valid-user
</Directory>
</VirtualHost>