core error - Script timed out before returning headers: wsgi.py - django

I'm running a Django app on Apache/2.4.6 (CentOS) with mod_wsgi.
When I visit my domain, after few minutes I get "Internal Server Error".
The log file shows the following error -
[core:error] [pid 9361] [client 132.72.41.107:55906] Script timed out before returning headers: wsgi.py
The config file in sites-enable folder -
<VirtualHost *:80>
ServerName www.meshi1.cs.bgu.ac.il
ServerAlias meshi1.cs.bgu.ac.il
DocumentRoot "/var/www/meshi1.cs.bgu.ac.il"
ErrorLog /var/www/meshi1.cs.bgu.ac.il/log/error.log
CustomLog /var/www/meshi1.cs.bgu.ac.il/log/requests.log combined
Alias /static /home/cluster/orelhaz/bin/rom_deshe/djangonautic1/static
<Directory /home/cluster/orelhaz/bin/rom_deshe/djangonautic1/static>
Require all granted
</Directory>
WSGIDaemonProcess djangonautic python-home=/home/cluster/orelhaz/bin/rom_deshe/myenv/lib/python3.6
WSGIProcessGroup djangonautic
WSGIScriptAlias / /home/cluster/orelhaz/bin/rom_deshe/djangonautic1/djangonautic/wsgi.py
<Directory /home/cluster/orelhaz/bin/rom_deshe/djangonautic1/djangonautic>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Thanks!

Related

How to fix? Error 500: No WSGI daemon process called... (Apache/ Django)

I have an internal Server Error 500 on my Django Server. When I check the error.log, I get the following error:
No WSGI daemon process called "..." has been configured: "..."
I hope someone can help me to fix this Error.
Here is my Apache config:
<VirtualHost *:80>
ServerAdmin ADMIN
ServerName DOMAIN
ErrorLog /home/USER/PROJECT/site/logs/error.log
CustomLog /home/PROJECT/PROJECT/site/logs/access.log combined
Alias /static /home/USER/PROJECT/static
<Directory /home/USER/PROJECT/static>
Require all granted
</Directory>
<Directory /home/USER/PROJECT/src/social>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess PROJECT python-path=/home/USER/PROJECT/ python-home=/home/USER/PROJECT/VIRTUALENV
WSGIProcessGroup PROJECT
WSGIScriptAlias / /home/USER/PROJECT/src/social/wsgi.py
</VirtualHost>
move your project path from /home/USER/PROJECT to /var/www/PROJECT
make sure you are chmod project folder --> sudo chmod -R 777 /project
if not work give your email to me for contact
<VirtualHost *:80>
# edit all /home/USER/PROJECT to /var/www/PROJECT
ServerAdmin ADMIN
ServerName DOMAIN
ErrorLog /home/USER/PROJECT/site/logs/error.log
CustomLog /home/PROJECT/PROJECT/site/logs/access.log combined
Alias /static /home/USER/PROJECT/static
<Directory /home/USER/PROJECT/static>
Require all granted
</Directory>
<Directory /home/USER/PROJECT/src/social> # here put path of where wsgi.py existing folder
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess PROJECT python-path=/home/USER/PROJECT/ python-home=/home/USER/PROJECT/VIRTUALENV
WSGIProcessGroup PROJECT
WSGIScriptAlias / /home/USER/PROJECT/src/social/wsgi.py
</VirtualHost>

Serving multiple domains with Django and Apache maps to one location only

I am attempting to setup Django to serve multiple sites (in the below configuration I am using examples www.domain1.com and www.domain2.com). I have installed Apache2 successfully, configured wsgi.py successfully (or so it seems).
I have built my appache configuration file to attempt the following mapping:
www.example1.com to serve from /var/www/mysite1
www.example2.com to serve from /var/www/mysite2
DNS A records for both example1.com and example2.com point to the same IP address.
The trouble with my setup as it exists is that both domain1.com and domain2.com map to the Django residing at /var/www/mysite1, despite the fact that I have (in theory) set them to map to their respective locations.
My apache config files are as follows, and both of the files (mysite1.conf and mysite2.conf) have had symlinks made for them using a2ensite:
#/etc/apache2/sites-available/mysite1.conf
WSGIDaemonProcess mysite processes=2 threads=25 python-home=/var/www/mysite1/myenv1 python-path=/var/www/mysite1/myenv1/mys
ite1
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite1/myenv1/mysite1/mysite1/wsgi.py
<VirtualHost *:80>
ServerName domain1.com
ServerAlias xx.xx.xx.xx
DocumentRoot /var/www/mysite1
ErrorLog ${APACHE_LOG_DIR}/mysite1-error.log
CustomLog ${APACHE_LOG_DIR}/mysite1-access.log combined
Alias /robots.txt /var/www/mysite1/myenv1/mysite1/static/robots.txt
Alias /favicon.ico /var/www/mysite1/myenv1/mysite1/static/favicon.ico
Alias /static/ /var/www/mysite1/myenv1/mysite1/static/
<Directory /var/www/mysite1/myenv1/mysite1/mysite1>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite1/myenv1/mysite1/static>
Require all granted
</Directory>
</VirtualHost>
#/etc/apache2/sites-available/mysite2.conf
WSGIDaemonProcess mysite2 processes=2 threads=25 python-home=/var/www/mysite2/myenv2 python-path=/var/www/mysite2/myenv
2/mysite2
WSGIProcessGroup mysite2
WSGIScriptAlias / /var/www/mysite2/myenv2/mysite2/mysite2/wsgi.py process-group=mysite2
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
ServerName domain2.com
ErrorLog ${APACHE_LOG_DIR}/mysite2-error.log
CustomLog ${APACHE_LOG_DIR}/mysite2-access.log combined
DocumentRoot /var/www/mysite2
Alias /robots.txt /var/www/mysite2/myenv2/mysite2/static/robots.txt
Alias /favicon.ico /var/www/mysite2/myenv2/mysite2/static/favicon.ico
Alias /static/ /var/www/mysite2/myenv2/mysite2/static/
<Directory /var/www/mysite2/myenv2/mysite2/mysite2>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/mysite2/myenv2/mysite2/static>
Require all granted
</Directory>
</VirtualHost>
An example wsgi.py file looks as below, and is working correctly (ie loading from the correct location) when it does load:
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite1.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite1.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
There are no errors being reported in either logs (/var/syslog/apache2/mysiteX.conf where x=1 or 2)
What am I doing wrong? How can I correct this so that domain2 starts to map to /var/www/mysite2?
Many thanks in advance!
The WSGI tags need to be inside the VirtualHost block for their respective domain names.
E.g.
<VirtualHost *:80>
ServerName domain1.com
ServerAlias xx.xx.xx.xx
DocumentRoot /var/www/mysite1
WSGIDaemonProcess mysite processes=2 threads=25 python-home=/var/www/mysite1/myenv1 python-path=/var/www/mysite1/myenv1/mys
ite1
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/mysite1/myenv1/mysite1/mysite1/wsgi.py
...
</VirtualHost>

Error 403: Forbidden You don't have permission to access / on this server with apache, mod-wsgi and django

I am new in django and apache. I want to publish my django website by apache and mod-wsgi.
when I start httpd.exe, I recieve 403 forbidden error in my browser.
my apache config is here
LoadFile "c:/users/zharf/appdata/local/continuum/anaconda3/envs/django/python36.dll"
LoadModule wsgi_module "c:/users/zharf/appdata/local/continuum/anaconda3/envs/django/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "c:/users/zharf/appdata/local/continuum/anaconda3/envs/django"
Alias /static/ /D:/user/JarfaSys/static/
<Directory D:/user/JarfaSys/static/>
AllowOverride none
Require all granted
</Directory>
WSGIScriptAlias / /D:/user/JarfaSys/JarfaSys/wsgi.py
WSGIPythonPath /D:/user/JarfaSys/
WSGIPassAuthorization On
<VirtualHost 127.0.0.1:443>
DocumentRoot D:/user/JarfaSys
Alias /favicon.ico D:/user/JarfaSys/JarfaSys/favicon.ico
Alias / /D:/user/JarfaSys/JarfaSys/wsgi.py
ServerName 127.0.0.1
SSLEngine on
SSLCertificateKeyFile C:/Users/zharf/TibiFiles/host.key
SSLCertificateFile C:/Users/zharf/TibiFiles/host.cert
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory D:/user/JarfaSys/JarfaSys/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
WSGIScriptAlias / /D:/user/JarfaSys/JarfaSys/wsgi.py
WSGIPythonPath /D:/user/JarfaSys/
WSGIPassAuthorization On
<Directory D:/user/JarfaSys/JarfaSys/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
wsgi.py is :
import os
import sys
path = "D:/Ghanbari/JarfaSys/JarfaSys"
if path not in sys.path:
sys.path.append(path)
os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "JarfaSys.settings")
#print os.getenv("DJANGO_SETTINGS_MODULE")
#print os.getenv("PYTHON_EGG_CACHE")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
error log file is here
[Fri Aug 23 16:29:26.827875 2019] [core:error] [pid 10784:tid 1092] (20024)The given path is misformatted or contained invalid characters: [client ::1:50025] AH00036: access to / failed (filesystem path 'C:/D:')
[Fri Aug 23 16:29:26.848875 2019] [core:error] [pid 10784:tid 1092] (20024)The given path is misformatted or contained invalid characters: [client ::1:50025] AH00036: access to /favicon.ico failed (filesystem path 'C:/D:'), referer: http://localhost/
Apache service user has access to my app directory.
I study many similar questions but the problem is not solved. any suggestions would be appreciated.
Here is an example of project setup in apache. You vhosts file has a few errors
Listen 443
<VirtualHost *:443>
ServerName localhost
ErrorLog "logs/logname-error.log"
CustomLog "logs/logname-access.log" common
WSGIScriptAlias / "C:\workspace\your_project_path\wsgi.py"
Alias /static/ C:/workspace/static/
<Directory C:\your_project_path>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
Remove the / Before the D:/... use the above as pattern.
and an example of a wsgi.py
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
activate_env = r"C:\your_virtual_environment_path\Scripts\activate_this.py"
with open(activate_env) as f:
exec(f.read(), {"__file__": activate_env})
from your_main import app as application

Serving Multiple WSGI Applications As Different Virtual Hosts on Apache

I have an EC2 AWS server on which I would like to host a couple of Django applications. Each of these apps has its own URL. For instance,
example1.com
example2.com
By itself, example1.com works. The problem is getting example2.com to work with it at the same time.
When I visit example2.com, I get an error:
DisallowedHost at /
Invalid HTTP_HOST header: 'example2.com'. You may need to add 'example2.com' to ALLOWED_HOSTS.
Request Method: GET
Request URL: http://example2.com
Django Version: 1.9.13
Exception Type: DisallowedHost
Exception Value:
Invalid HTTP_HOST header: 'example2.com'. You may need to add 'example2.com' to ALLOWED_HOSTS.
Exception Location: /var/www/vhosts/example1/example1-env/lib/python3.5/site-packages/django/http/request.py in get_host, line 109
Python Executable: /usr/bin/python3
Python Version: 3.5.1
Python Path:
['/usr/lib64/python3.5',
'/usr/lib64/python3.5/plat-linux',
'/usr/lib64/python3.5/lib-dynload',
'/usr/local/lib64/python3.5/site-packages',
'/usr/local/lib/python3.5/site-packages',
'/usr/lib64/python3.5/dist-packages',
'/usr/lib/python3.5/dist-packages',
'/var/www/vhosts/example1/',
'/var/www/vhosts/example1/example1-env/lib/python3.5/site-packages']
Server time: Wed, 14 Jun 2017 20:31:27 +0000
As you can see, somehow Apache is trying to use the virtual environment of example1.com when it serves example2.com. How could I correct that? Each one should be served with its own virtualenv.
Here is the Apache configuration file:
<VirtualHost *:80>
# This is name based virtual hosting. So place an appropriate server name
# here. Example: django.devsrv.local
ServerName example1.com
WSGIDaemonProcess example1 python-home=/var/www/vhosts/example1/example1-env
WSGIProcessGroup %{GLOBAL}
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/example1/example1/wsgi.py
<Directory /var/www/vhosts/example1/>
Require all granted
</Directory>
Alias /static/ /var/www/vhosts/example1/static/
<Directory /var/www/vhosts/example1/static/>
Order deny,allow
Allow from all
</Directory>
Alias /media/ /var/www/vhosts/example1/media/
<Directory /var/www/vhosts/example1/media/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
# This is name based virtual hosting. So place an appropriate server name
# here. Example: django.devsrv.local
ServerName example2.com
WSGIDaemonProcess example2 python-home=/var/www/vhosts/example2/example2-env
WSGIProcessGroup %{GLOBAL}
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/example2/example2/wsgi.py
<Directory /var/www/vhosts/example2/>
Require all granted
</Directory>
Alias /static/ /var/www/vhosts/example2/static/
<Directory /var/www/vhosts/example2/static/>
Order deny,allow
Allow from all
</Directory>
Alias /media/ /var/www/vhosts/example2/media/
<Directory /var/www/vhosts/example2/media/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Edit:
Having read some suggestions in the comments, I have come to this. This still does not work.
ServerName example1.com
WSGIDaemonProcess example1 display-name=%{GROUP} python-path=/var/www/vhosts/example1/ python-home=/var/www/vhosts/example1/example1-env/
WSGIApplicationGroup %{GLOBAL}
WSGIProcessGroup example1
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/example1/example1/wsgi.py process-group=example1
...
ServerName example2.com
WSGIDaemonProcess example2 display-name=%{GROUP} python-home=/var/www/vhosts/example2/example2-env/ python-path=/var/www/vhosts/example2/
WSGIApplicationGroup %{GLOBAL}
WSGIProcessGroup example2
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/example2/example2/wsgi.py process-group=example2
The following configuration worked for me. In short, it serves two different Django applications at example1.com and example2.com using their respective virtual environments.
As you can see, inserting the ServerAlias AND ServerName made all the difference, alongside a couple of other corrections by suggested by the community.
Apache configuration:
<IfModule !wsgi_module>
LoadModule wsgi_module modules/mod_wsgi.so
</IfModule>
<VirtualHost *:80>
ServerName www.example1.com
ServerAlias example1.com
WSGIDaemonProcess example1 display-name=%{GROUP} python-path=/var/www/vhosts/example1/ python-home=/var/www/vhosts/example1/example1-env/
WSGIApplicationGroup %{GLOBAL}
WSGIProcessGroup example1
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/example1/example1/wsgi.py process-group=example1
<Directory /var/www/vhosts/example1/>
Require all granted
</Directory>
Alias /static/ /var/www/vhosts/example1/static/
<Directory /var/www/vhosts/example1/static/>
Order deny,allow
Allow from all
</Directory>
Alias /media/ /var/www/vhosts/example1/media/
<Directory /var/www/vhosts/example1/media/>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.example2.com
ServerAlias example2.com
WSGIDaemonProcess example2 display-name=%{GROUP} python-home=/var/www/vhosts/example2/example2-env/ python-path=/var/www/vhosts/example2/
WSGIApplicationGroup %{GLOBAL}
WSGIProcessGroup example2
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/example2/example2/wsgi.py process-group=example2
<Directory /var/www/vhosts/example2/>
Require all granted
</Directory>
Alias /static/ /var/www/vhosts/example2/static/
<Directory /var/www/vhosts/example2/static/>
Order deny,allow
Allow from all
</Directory>
Alias /media/ /var/www/vhosts/example2/media/
<Directory /var/www/vhosts/example2/media/>
</VirtualHost>

Unable to connect to WSGI daemon process 'sampleapp'

I tried to install django in ubuntu server and i had 503 error in error.log
my apache2.conf is:
<VirtualHost x.xxx.xxx.xxx:8080>
ServerAlias www.samplesite.com
ServerAdmin info#samplesite.com
DocumentRoot /var/www/sampleapp/
ScriptAlias /cgi-bin/ /var/www/sampleapp/cgi-bin/
Alias /vstats/ /var/www/sampleapp/stats/
Alias /error/ /var/www/sampleapp/document_error
#SuexecUserGroup admin admin
CustomLog /var/log/apache2/domains/sampleapp.ir.bytes bytes
CustomLog /var/log/apache2/domains/sampleapp.ir.log combined
ErrorLog /var/log/apache2/domains/sampleapp.ir.error.log
WSGIProcessGroup sampleapp
WSGIScriptAlias /sampleapp /var/www/sampleapp/sampleapp/wsgi.py
WSGIDaemonProcess sampleapp python-path=/var/www/sampleapp:/var/www /sampleapp/envme/lib/python3.4/site-packages
<Directory /var/www/sampleapp/static/>
Require all granted
</Directory>
<Directory /var/www/sampleapp/media/>
Require all granted
</Directory>
<Directory /var/www/sampleapp/sampleapp/>
<Files wsgi.py>
require all granted
</Files>
</Directory>
<Directory /var/www/sampleapp/>
AllowOverride All
Options +Includes +Indexes +ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and i have this error in my error.log:
(13)Permission denied: [client x.xxx.xx.xxx:59504] mod_wsgi (pid=26905): Unable to connect to WSGI daemon process 'sampleapp' on '/var/run/apache2/wsgi.26899.0.1.sock' as user with uid=1005.
I lost 2 days trying to solve it,
You can refer this url,
http://code.google.com/p/modwsgi/wiki/ConfigurationIssues#Location_Of_UNIX_Sockets
Adding this,
WSGISocketPrefix run/wsgi
will solve the error. The solution is to change where the socket files are kept to a location where Apache user can read them.