Django + Apache - wsgi trouble - django

I've been working with Django locally and now I'm trying to push some code to a production Apache environment on an Ubuntu server I have running (http://www.youtube.com/watch?v=hBMVVruB9Vs).
However, I just get a list of files in the directory and nothing else. First of all I ensured that Python was install by running the command Python at the terminal.
I've installed apaache and mod wsgi with the following commands:
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi
And I've tested to see that its enabled.
Here is my wsgi file firstweb.wsgi which is located in root:
import os
import sys
sys.path.append('/var/www/firstweb')
os.environ['DJANGO_SETTINGS_MODULE'] = 'firstweb.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Here is my firstweb.conf file:
<VirtualHost *:80>
WSGIScriptAlias / /firstweb.wsgi
Alias /static /var/www/firstweb/static
<Directory /var/www/firstweb/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and my Django project is located in: /var/www/firstweb/
I honestly can't work out what is wrong here, within the video it is running fine! :(
Edit, here is error log:
[Sat Feb 16 16:19:31 2013] [notice] Apache/2.2.22 (Ubuntu) configured -- resuming normal operations
[Sat Feb 16 16:20:46 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:20:47 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:20:47 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:20:47 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:37:05 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:37:06 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:37:06 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:37:06 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:37:17 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:20 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:25 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:25 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:37:26 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:38:01 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:39:19 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:39:20 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:39:20 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:39:20 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:39:24 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:39:42 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:48:00 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:48:02 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:49:51 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:49:52 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:49:52 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:49:52 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:49:55 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:49:56 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:49:58 2013] [error] [client 131.231.153.48] File does not exist: /var/www/favicon.ico
[Sat Feb 16 16:53:21 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:53:22 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:53:22 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:53:22 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 16:55:34 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 16:55:35 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 16:55:35 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 16:55:35 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Sat Feb 16 17:00:07 2013] [notice] caught SIGTERM, shutting down
[Sat Feb 16 17:00:08 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Feb 16 17:00:08 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Feb 16 17:00:08 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations

Try configuring your virtualhost like so:
<Directory /var/www/firstweb/static>
Order allow,deny
Option Indexes
Allow from all
</Directory>
WSGIScriptAlias / /full-system-path-to/firstweb/wsgi.py
If that doesn't work - just make a change to the Directory tag and add static to the end like I have above - I think by not adding static, it's displaying the files in the directory

Configuring your virtualhost like:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/production/myApp
<Directory />
Order Deny,Allow
Deny from all
Options None
AllowOverride None
</Directory>
<Directory /var/production/myApp>
Options None
AllowOverride None
Order allow,deny
allow from all
</Directory>
WSGIDaemonProcess mysite.com python-path=/var/production/myApp:/var/production/myApp/venv/lib/python2.7/site-packages
WSGIProcessGroup misite.com
WSGIScriptAlias / /var/production/myApp/myApp/wsgi.py
Alias /static /var/production/myApp/static
<Directory /var/production/myApp/static>
Options None
AllowOverride None
Order Allow,Deny
Allow from all
</Directory>
Replaces "/var/production/myApp" to your app path
If you need more help look at this tutorial

Question 1: Did you enable the wsgi mod?
sudo a2enmod mod-wsgi
Question 2: Where are your AddHandler statements?
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
AllowOverride None
Order allow,deny
allow from all
</Directory>
I don't think apache knows how to associate .wsgi files to the wsgi application.

Related

Django 4 with Apache 2.4 on Ubuntu 22.04 initially loading but then stops working until Apache restart

I deployed my Django 4 project with a SQLITE3 DB using python 3.10 on an Ubuntu 22.04 Server instance on a virtual machine on my Synology NAS. I am using the WSGI module, which is to my knowledge the only way to do this, right?
My Synology NAS has an Intel Celeron processes and 10GB RAM (2 cores and 6 GB are available to the virtual machine, I also tried first with 4 GB)
Now after I managed that my website can be called and is displayed I am facing the issue that I can call any page initially I want and it displays as expected BUT then the browser tab indicates by a moving circle that still something is loading and I cannot navigate to any other URL within my application. even the language is displayed correctly depending on the browser language.
It also happens that after I restarted apache the next page loaded. Doing this I was even able to login to the admin UI in 2 steps, so the database is obviously accessible.
Meanwhile increased the log level to trace1 of the Apache server and now can see that after 5 minutes the process gets killed and restarted for any reason but at least my environment variables are correctly loaded: This I can see by using print statements to show them in the logs. I also granted explicit complete rights für :www-data to my data base as it seems to me like the application or Apache has an issue with maybe writuing to the database.
Below you find extracts of the erorr log and Myebsite.log Yes, I called it like that :-)
So I hope somebody here has the right clue for me, to get this running.
Thank you in advance!
EXTRACT from MyWebsite.log
Between 20:43 and 20:48 nothing happens until the process stops.
[Thu Jan 26 20:43:24.001088 2023] [deflate:trace1] [pid 834] mod_deflate.c(734): [client 192.168.175.42:51447] token: 'gzip' - q: ''
[Thu Jan 26 20:43:24.158541 2023] [authz_core:debug] [pid 832] mod_authz_core.c(815): [client 192.168.175.42:51449] AH01626: authorization result of Require all granted: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.158605 2023] [authz_core:debug] [pid 832] mod_authz_core.c(815): [client 192.168.175.42:51449] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.158822 2023] [deflate:trace1] [pid 832] mod_deflate.c(734): [client 192.168.175.42:51449] token: 'gzip' - q: '', referer: http://192.168.175.56/
[Thu Jan 26 20:43:24.167348 2023] [deflate:debug] [pid 832] mod_deflate.c(869): [client 192.168.175.42:51449] AH01384: Zlib: Compressed 153402 to 22635 : URL /static/homepage/bootstrap.min.css, referer: http://192.168.175.56/
192.168.175.42 - - [26/Jan/2023:20:43:24 +0000] "GET /static/homepage/bootstrap.min.css HTTP/1.1" 200 22993 "http://192.168.175.56/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:23.835110 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Daemon process deadlock timer expired, stopping process 'MyWebsite'.
[Thu Jan 26 20:48:23.835355 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Shutdown requested 'MyWebsite'.
[Thu Jan 26 20:48:24.023436 2023] [wsgi:error] [pid 834] (70007)The timeout specified has expired: [client 192.168.175.42:51447] mod_wsgi (pid=834): Failed to proxy response from daemon.
[Thu Jan 26 20:48:24.023582 2023] [deflate:debug] [pid 834] mod_deflate.c(869): [client 192.168.175.42:51447] AH01384: Zlib: Compressed 9409 to 3096 : URL /
192.168.175.42 - - [26/Jan/2023:20:43:13 +0000] "GET / HTTP/1.1" 200 3562 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:24.087213 2023] [authz_core:debug] [pid 834] mod_authz_core.c(815): [client 192.168.175.42:51447] AH01626: authorization result of Require all granted: granted, referer: http://192.168.175.56/
[Thu Jan 26 20:48:24.087306 2023] [authz_core:debug] [pid 834] mod_authz_core.c(815): [client 192.168.175.42:51447] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.175.56/
192.168.175.42 - - [26/Jan/2023:20:48:24 +0000] "GET /static/homepage/minion_logo.png HTTP/1.1" 304 249 "http://192.168.175.56/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61"
[Thu Jan 26 20:48:28.836028 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Aborting process 'MyWebsite'.
[Thu Jan 26 20:48:28.836241 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Exiting process 'MyWebsite'.
[Thu Jan 26 20:48:29.768996 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Attach interpreter ''.
[Thu Jan 26 20:48:29.791601 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Adding '/var/www/MyWebsite/MyWebsite' to path.
[Thu Jan 26 20:48:29.793603 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 0 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794397 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 1 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794441 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 4 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794595 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 3 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794677 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 2 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.794863 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 5 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795137 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 6 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795248 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 7 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.795994 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 14 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796116 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 13 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796215 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 12 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796293 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 9 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796373 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 11 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796496 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 10 in daemon process 'MyWebsite'.
[Thu Jan 26 20:48:29.796591 2023] [wsgi:debug] [pid 1239] src/server/mod_wsgi.c(9142): mod_wsgi (pid=1239): Started thread 8 in daemon process 'MyWebsite'.
EXTRACT error.log
[Thu Jan 26 20:42:52.685411 2023] [watchdog:debug] [pid 828] mod_watchdog.c(445): AH010033: Watchdog: Running with WatchdogInterval 1000ms
[Thu Jan 26 20:42:52.685641 2023] [watchdog:debug] [pid 828] mod_watchdog.c(454): AH02974: Watchdog: found parent providers.
[Thu Jan 26 20:42:52.685661 2023] [watchdog:debug] [pid 828] mod_watchdog.c(500): AH02977: Watchdog: found child providers.
[Thu Jan 26 20:42:52.685678 2023] [watchdog:debug] [pid 828] mod_watchdog.c(508): AH02978: Watchdog: Looking for child (_singleton_).
[Thu Jan 26 20:42:52.685694 2023] [watchdog:debug] [pid 828] mod_watchdog.c(508): AH02978: Watchdog: Looking for child (_default_).
[Thu Jan 26 20:42:52.686259 2023] [wsgi:debug] [pid 828] src/server/mod_wsgi.c(8512): mod_wsgi (pid=828): Socket for 'MyWebsite' is '/var/run/apache2/wsgi.828.0.1.sock'.
[Thu Jan 26 20:42:52.686405 2023] [wsgi:debug] [pid 828] src/server/mod_wsgi.c(8581): mod_wsgi (pid=828): Listen backlog for socket '/var/run/apache2/wsgi.828.0.1.sock' is '100'.
[Thu Jan 26 20:42:52.690541 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Starting process 'MyWebsite' with uid=33, gid=33 and threads=15.
[Thu Jan 26 20:42:52.705603 2023] [mpm_prefork:notice] [pid 828] AH00163: Apache/2.4.52 (Ubuntu) mod_wsgi/4.9.0 Python/3.10 configured -- resuming normal operations
[Thu Jan 26 20:42:52.705648 2023] [mpm_prefork:info] [pid 828] AH00164: Server built: 2022-09-30T04:09:50
[Thu Jan 26 20:42:52.705701 2023] [core:notice] [pid 828] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jan 26 20:42:52.705719 2023] [core:debug] [pid 828] log.c(1570): AH02639: Using SO_REUSEPORT: yes (1)
[Thu Jan 26 20:42:52.705736 2023] [mpm_prefork:debug] [pid 828] prefork.c(953): AH00165: Accept mutex: none (default: pthread)
[Thu Jan 26 20:42:52.706664 2023] [watchdog:debug] [pid 831] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.707440 2023] [watchdog:debug] [pid 832] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.712781 2023] [watchdog:debug] [pid 834] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.713025 2023] [watchdog:debug] [pid 833] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.718786 2023] [wsgi:info] [pid 831] mod_wsgi (pid=831): Initializing Python.
[Thu Jan 26 20:42:52.719577 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Python home /var/www/MyWebsite/MyWebsite/venv.
[Thu Jan 26 20:42:52.719790 2023] [wsgi:info] [pid 832] mod_wsgi (pid=832): Initializing Python.
[Thu Jan 26 20:42:52.720365 2023] [wsgi:info] [pid 834] mod_wsgi (pid=834): Initializing Python.
[Thu Jan 26 20:42:52.720460 2023] [wsgi:info] [pid 833] mod_wsgi (pid=833): Initializing Python.
[Thu Jan 26 20:42:52.721846 2023] [watchdog:debug] [pid 830] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:42:52.722049 2023] [wsgi:info] [pid 830] mod_wsgi (pid=830): Initializing Python.
[Thu Jan 26 20:42:52.796422 2023] [wsgi:info] [pid 829] mod_wsgi (pid=829): Initializing Python.
[Thu Jan 26 20:42:53.972677 2023] [wsgi:info] [pid 834] mod_wsgi (pid=834): Attach interpreter ''.
[Thu Jan 26 20:42:53.999176 2023] [wsgi:info] [pid 832] mod_wsgi (pid=832): Attach interpreter ''.
[Thu Jan 26 20:42:54.057680 2023] [wsgi:info] [pid 833] mod_wsgi (pid=833): Attach interpreter ''.
[Thu Jan 26 20:42:54.071090 2023] [wsgi:info] [pid 831] mod_wsgi (pid=831): Attach interpreter ''.
[Thu Jan 26 20:42:54.113752 2023] [wsgi:info] [pid 830] mod_wsgi (pid=830): Attach interpreter ''.
[Thu Jan 26 20:43:14.732936 2023] [watchdog:debug] [pid 1127] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:43:14.733171 2023] [wsgi:info] [pid 1127] mod_wsgi (pid=1127): Initializing Python.
[Thu Jan 26 20:43:14.792782 2023] [wsgi:info] [pid 1127] mod_wsgi (pid=1127): Attach interpreter ''.
[Thu Jan 26 20:43:24.421107 2023] [watchdog:debug] [pid 1128] mod_watchdog.c(559): AH02980: Watchdog: nothing configured?
[Thu Jan 26 20:43:24.421327 2023] [wsgi:info] [pid 1128] mod_wsgi (pid=1128): Initializing Python.
[Thu Jan 26 20:43:24.485083 2023] [wsgi:info] [pid 1128] mod_wsgi (pid=1128): Attach interpreter ''.
[Thu Jan 26 20:48:29.725192 2023] [wsgi:info] [pid 828] mod_wsgi (pid=829): Process 'MyWebsite' has died, deregister and restart it.
[Thu Jan 26 20:48:29.725334 2023] [wsgi:info] [pid 828] mod_wsgi (pid=829): Process 'MyWebsite' has been deregistered and will no longer be monitored.
[Thu Jan 26 20:48:29.726543 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Starting process 'MyWebsite' with uid=33, gid=33 and threads=15.
[Thu Jan 26 20:48:29.730090 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Python home /var/www/MyWebsite/MyWebsite/venv.
[Thu Jan 26 20:48:29.730296 2023] [wsgi:info] [pid 1239] mod_wsgi (pid=1239): Initializing Python.
Apache.conf seetings (i removed all commented lines)
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 1
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel trace1
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
MyWebsite.conf
VirtualHost *:80>
ServerAdmin admin#MyWebsite.com
ServerName MyWebsite.com
ServerAlias www.MyWebsite.com
DocumentRoot /var/www/MyWebsite/MyWebsite/
ErrorLog ${APACHE_LOG_DIR}/MyWebsite.log
CustomLog ${APACHE_LOG_DIR}/MyWebsite.log combined
Alias /static /var/www/MyWebsite/MyWebsite/static
<Directory /var/www/MyWebsite/MyWebsite/static>
Require all granted
</Directory>
Alias /media /var/www/MyWebsite/MyWebsite/media
<Directory /var/www/MyWebsite/MyWebsite/media>
Require all granted
</Directory>
<Directory /var/www/MyWebsite/MyWebsite/MyWebsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess MyWebsite python-path=/var/www/MyWebsite/MyWebsite python-home=/var/www/MyWebsite/MyWebsite/venv
WSGIProcessGroup MyWebsite
WSGIScriptAlias / /var/www/MyWebsite/MyWebsite/MyWebsite/wsgi.py
</VirtualHost>
WSGI.py
"""
WSGI config for MyWebsite 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/4.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyWebsite.settings')
application = get_wsgi_application()
from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)
List of Packages in VENV (python version: Python 3.10.6)
Package Version
----------------- -------
asgiref 3.6.0
autopep8 2.0.1
Django 4.1.4
django-countries 7.5
pip 22.0.2
pycodestyle 2.10.0
python-dotenv 0.21.0
setuptools 59.6.0
sqlparse 0.4.3
tomli 2.0.1
typing_extensions 4.4.0
tzdata 2022.7
its been a while but ... this is the steps I just took from a container based on Ubuntu Image:
> apt-get install apache2
> apt-get install apache2-dev
> ...env/bin/activate # activate virt env
> apt-get install mod_wsgi
> mod_wsgi-express module-config # run the command and copy 2 output lines (see below example) from terminal to apache config file (not inside vhost/host)
something like:
LoadModule wsgi_module "/var/www/project/env/lib/python3.10/site-packages/mod_wsgi/server/mod_wsgi-py310.cpython-310-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/project/env"
the rest seems ok in your vhost conf etc.

Apache Error during SSL Handshake with remote server

I have apache listening on 443, and web app nodejs listening on 6969 on EC2 linux server.
I have ssl.conf file
<VirtualHost _default_:443>
SSLEngine On
SSLProxyEngine On
ProxyRequests Off
ProxyPreserveHost On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ServerAdmin ***#gmail.com
DocumentRoot /var/www/html/***
ServerName ***
SSLCertificateFile "***/certificate.crt"
SSLCertificateChainFile "***/ca_bundle.crt"
SSLCertificateKeyFile "***/private.key"
ProxyPass / https://127.0.0.1:6969/
ProxyPassReverse / https://127.0.0.1:6969/
<Directory "/var/www/html/***">
Order deny,allow
Allow from all
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
and file httpd/error_log
[Sun Jul 12 18:56:27.176297 2020] [proxy:error] [pid 32374:tid 140253401167616] (20014)Internal error (specific information not available): [client 117.6.62.***:32539] AH01084: pass request body failed to 127.0.0.1:6969 (127.0.0.1)
[Sun Jul 12 18:56:27.176334 2020] [proxy:error] [pid 32374:tid 140253401167616] [client 117.6.62.***:32539] AH00898: Error during SSL Handshake with remote server returned by /
[Sun Jul 12 18:56:27.176339 2020] [proxy_http:error] [pid 32374:tid 140253401167616] [client 117.6.62.***:32539] AH01097: pass request body failed to 127.0.0.1:6969 (127.0.0.1) from 117.6.62.*** ()
[Sun Jul 12 18:56:34.161784 2020] [proxy:error] [pid 32374:tid 140253401167616] (20014)Internal error (specific information not available): [client 117.6.62.***:32542] AH01084: pass request body failed to 127.0.0.1:6969 (127.0.0.1)
[Sun Jul 12 18:56:34.161831 2020] [proxy:error] [pid 32374:tid 140253401167616] [client 117.6.62.***:32542] AH00898: Error during SSL Handshake with remote server returned by /
[Sun Jul 12 18:56:34.161836 2020] [proxy_http:error] [pid 32374:tid 140253401167616] [client 117.6.62.***:32542] AH01097: pass request body failed to 127.0.0.1:6969 (127.0.0.1) from 117.6.62.*** ()
[Sun Jul 12 18:56:47.451390 2020] [mpm_event:notice] [pid 32156:tid 140253690120384] AH00492: caught SIGWINCH, shutting down gracefully
[Sun Jul 12 18:56:48.524967 2020] [suexec:notice] [pid 32494:tid 140512587598016] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Sun Jul 12 18:56:48.549325 2020] [lbmethod_heartbeat:notice] [pid 32494:tid 140512587598016] AH02282: No slotmem from mod_heartmonitor
[Sun Jul 12 18:56:48.552155 2020] [mpm_event:notice] [pid 32494:tid 140512587598016] AH00489: Apache/2.4.43 () OpenSSL/1.0.2k-fips configured -- resuming normal operations
[Sun Jul 12 18:56:48.552179 2020] [core:notice] [pid 32494:tid 140512587598016] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
Can anyone suggest what I am doing wrong?
This was as the result of trying to communicate using HTTPS to the internal node application.
The application was running on HTTPS, updating to HTTP internally resolved this.

how to solve mod_wsgi python conflict error

Hi all i am using Apache mod_wsgi to deploy a python application but i am getting internal server error as:
[Fri Nov 17 17:26:01.285539 2017] [mpm_event:notice] [pid 25751:tid 140495002072960] AH00491: caught SIGTERM, shutting down
[Fri Nov 17 17:26:02.395406 2017] [so:warn] [pid 26122:tid 140693819524992] AH01574: module wsgi_module is already loaded, skipping
[Fri Nov 17 17:26:02.396961 2017] [wsgi:warn] [pid 26123:tid 140693819524992] mod_wsgi: Compiled for Python/2.7.11.
[Fri Nov 17 17:26:02.396983 2017] [wsgi:warn] [pid 26123:tid 140693819524992] mod_wsgi: Runtime using Python/2.7.12.
[Fri Nov 17 17:26:02.397621 2017] [mpm_event:notice] [pid 26123:tid 140693819524992] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Fri Nov 17 17:26:02.397650 2017] [core:notice] [pid 26123:tid 140693819524992] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 17 17:26:28.707573 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] mod_wsgi (pid=26126): Target WSGI script '/home/rajesh/mymapproxy/config.py' cannot be loaded as Python module.
[Fri Nov 17 17:26:28.707618 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] mod_wsgi (pid=26126): Exception occurred processing WSGI script '/home/rajesh/mymapproxy/config.py'.
[Fri Nov 17 17:26:28.707636 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] Traceback (most recent call last):
[Fri Nov 17 17:26:28.707655 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] File "/home/rajesh/mymapproxy/config.py", line 9, in
[Fri Nov 17 17:26:28.707703 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] from mapproxy.wsgiapp import make_wsgi_app
[Fri Nov 17 17:26:28.707747 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] ImportError: No module named mapproxy.wsgiapp
How can i fix this issue
Here is my apache configration: /etc/apche2/site-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias /mapproxy /home/rajesh/workspace/mymapproxy/config.py
WSGIApplicationGroup %{GLOBAL}
<Directory "/home/rajesh/workspace/mymapproxy/">
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This is my /home/rajesh/workspace/mymapproxy/config.py
from mapproxy.wsgiapp import make_wsgi_app
application = make_wsgi_app(r'/etc/mapproxy.yaml')

How to use Django with Apache?

Can someone help me and say whats wrong?
I need to use Django + Apache.
When I try to start Apache it shows me error: The requested operation has failed.
I tried to change Listen 80 to different values but it didnt help. Also this error appears after adding next settings to httpd.conf file (without these settings Apache start fine):
LoadModule wsgi_module modules/mod_wsgi.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
I use:
1) Apache 2.4 (x64)
2) Python 3.5.2 (x64)
3) Django 1.10.5
4) mod_wsgi‑4.5.15+ap24vc14‑cp35‑cp35m‑win_amd64.whl
5) Windows 8.1 (x64)
Maybe I use wrong mod_wsgi? I take mod_wsgi.cp35-win_amd64.pyd file from mod_wsgi‑4.5.15+ap24vc14‑cp35‑cp35m‑win_amd64.whl archive and rename that file to mod_wsgi.so. After that put that file to modules folder of Apache.
error.log file looks like this:
[Wed Jun 14 21:42:30.381146 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00455: Apache/2.4.2 (Win64) configured -- resuming normal operations
[Wed Jun 14 21:42:30.381146 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00456: Server built: May 11 2012 20:42:30
[Wed Jun 14 21:42:30.381146 2017] [core:notice] [pid 11892:tid 692] AH00094: Command line: 'C:\\Program Files\\Apache2.4\\bin\\httpd.exe -d C:/Program Files/Apache2.4 -f C:\\Program Files\\Apache2.4\\conf\\httpd.conf -d C:\\Program Files\\Apache2.4\\.'
[Wed Jun 14 21:42:30.381146 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00418: Parent: Created child process 13624
[Wed Jun 14 21:42:30.646739 2017] [mpm_winnt:notice] [pid 13624:tid 328] AH00354: Child: Starting 64 worker threads.
[Wed Jun 14 21:42:40.736467 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed Jun 14 21:42:42.759516 2017] [mpm_winnt:notice] [pid 13624:tid 328] AH00364: Child: All worker threads have exited.
[Wed Jun 14 21:42:42.775140 2017] [mpm_winnt:notice] [pid 11892:tid 692] AH00430: Parent: Child process exited successfully.
[Wed Jun 14 21:42:51.755536 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00455: Apache/2.4.2 (Win64) configured -- resuming normal operations
[Wed Jun 14 21:42:51.756537 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00456: Server built: May 11 2012 20:42:30
[Wed Jun 14 21:42:51.756537 2017] [core:notice] [pid 7988:tid 696] AH00094: Command line: 'C:\\Program Files\\Apache2.4\\bin\\httpd.exe -d C:/Program Files/Apache2.4 -f C:\\Program Files\\Apache2.4\\conf\\httpd.conf -d C:\\Program Files\\Apache2.4\\.'
[Wed Jun 14 21:42:51.757538 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00418: Parent: Created child process 8692
[Wed Jun 14 21:42:51.973446 2017] [mpm_winnt:notice] [pid 8692:tid 636] AH00354: Child: Starting 64 worker threads.
[Wed Jun 14 21:59:11.710766 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed Jun 14 21:59:13.712698 2017] [mpm_winnt:notice] [pid 8692:tid 636] AH00364: Child: All worker threads have exited.
[Wed Jun 14 21:59:13.731009 2017] [mpm_winnt:notice] [pid 7988:tid 696] AH00430: Parent: Child process exited successfully.
[Wed Jun 14 23:12:16.868389 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00455: Apache/2.4.2 (Win64) configured -- resuming normal operations
[Wed Jun 14 23:12:16.869389 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00456: Server built: May 11 2012 20:42:30
[Wed Jun 14 23:12:16.869389 2017] [core:notice] [pid 7988:tid 692] AH00094: Command line: 'C:\\Program Files\\Apache2.4\\bin\\httpd.exe -d C:/Program Files/Apache2.4 -f C:\\Program Files\\Apache2.4\\conf\\httpd.conf -d C:\\Program Files\\Apache2.4\\.'
[Wed Jun 14 23:12:16.870391 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00418: Parent: Created child process 7152
[Wed Jun 14 23:12:17.107601 2017] [mpm_winnt:notice] [pid 7152:tid 616] AH00354: Child: Starting 64 worker threads.
[Wed Jun 14 23:12:24.939591 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Wed Jun 14 23:12:26.941397 2017] [mpm_winnt:notice] [pid 7152:tid 616] AH00364: Child: All worker threads have exited.
[Wed Jun 14 23:12:26.960081 2017] [mpm_winnt:notice] [pid 7988:tid 692] AH00430: Parent: Child process exited successfully.
wsgi.py:
import os, sys
sys.path.append('C:/Program Files/Apache2.4/htdocs/RMS/RMS')
sys.path.append('C:/Program Files/Apache2.4/htdocs/RMS')
os.environ.setdefault["DJANGO_SETTINGS_MODULE"] = "RMS.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandlers()
httpd-vhosts.conf:
<VirtualHost *:8080>
WSGIScriptAlias /rms 'C:/Program Files/Apache2.4/htdocs/RMS/RMS/wsgi.py'
Alias /media/ 'C:/Program Files/Apache2.4/htdocs/RMS/media'
Alias /media/ 'C:/Program Files/Apache2.4/htdocs/RMS/media'
<Directory "C:/Program Files/Apache2.4/htdocs/RMS/static">
<Files wsgi.py>
Order allow, deny
Allow from all
</Files>
</Directory>
<Directory "C:/Program Files/Apache2.4/htdocs/RMS/media">
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
httpd.conf:
Listen 8080
LoadModule wsgi_module modules/mod_wsgi.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
The method Graham Dumpleton mentions is the way that worked for me, I was lucky enough to come across this item: modwgsi Google Group again by Graham.
Install mod_wsgi using pip (preferably into a virtualenv)
Run mod_wsgi-express module-config to get the settings to copy into your httpd.conf file, I chose to copy these above the LoadModules list.
Don't look to move and rename the .pyd file, leave it alone. To test, create a helloworld.wsgi with the following content:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
In your VirtualHost, create a WSGIScriptAlias pointing to the wsgi file created, e.g. WSGIScriptAlias /test C:/wsgitest/helloworld.wsgi

mod_wsgi cannot be loaded as Python module

I'm trying to access a Django application using apache and I'm getting Internal Server Error. I've opened the logs to see what is going on and I found this:
[Thu Jun 23 03:10:03 2016] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jun 23 03:10:03 2016] [notice] Digest: generating secret for digest authentication ...
[Thu Jun 23 03:10:03 2016] [notice] Digest: done
[Thu Jun 23 03:10:03 2016] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] mod_wsgi (pid=5612): Target WSGI script '/home/TaskManagement/teamwork/wsgi.py' cannot be loaded as Python module.
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] mod_wsgi (pid=5612): Exception occurred processing WSGI script '/home/TaskManagement/teamwork/wsgi.py'.
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] Traceback (most recent call last):
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/TaskManagement/teamwork/wsgi.py", line 15, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.core.wsgi import get_wsgi_application
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/__init__.py", line 1, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.utils.version import get_version
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/utils/version.py", line 7, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.utils.lru_cache import lru_cache
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/utils/lru_cache.py", line 28
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] fasttypes = {int, str, frozenset, type(None)},
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] ^
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] SyntaxError: invalid syntax
I'm using python 3.4, Django 1.9, apache 2.2.
and here is my apache configuration:
WSGISocketPrefix /var/run/wsgi
WSGIScriptAlias / /home/TaskManagement/teamwork/wsgi.py process-group=hrm.jodod.info
WSGIDaemonProcess hrm.jodod.info python-path=/home/TaskManagement:/home/py3venv/lib/python3.4/site-packages
WSGIProcessGroup hrm.jodod.info
Alias /robots.txt /home/TaskManagement/robots.txt
Alias /favicon.ico /home/TaskManagement/favicon.ico
Alias /static/ /home/TaskManagement/static/
<Directory /path/to/mysite.com/static>
Order deny,allow
Allow from all
</Directory>
<Directory /home/TaskManagement/teamwork>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
and here is my wsgi.py file:
import os
import sys
sys.path.append('/home/TaskManagement')
sys.path.append('/home/TaskManagement/teamwork')
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
application = get_wsgi_application()
Can anybody figure out what am I doing wrong?
Python/2.6.6 configured -- resuming normal operations
Looks like your mod_wsgi is compiled against Python 2.6.6 and you're trying to run Python3 code with it. The Set syntax you are seeing in the error appeared in Py3. Recompile mod_wsgi and try again.
Your wsgi.py line 9 has to be
os.environ["DJANGO_SETTINGS_MODULE"] = "teamwork.settings"
if the directory it's stored is called teamwork (your project's name)
also in your manage.py it has to be "teamwork.settings"