wsgi.py
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gis_api.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd.conf
ServerName 127.0.0.1:81
LoadFile "C:/Users/test/AppData/Local/Programs/Python/Python310/python310.dll"
LoadModule wsgi_module "C:/Users/test/AppData/Local/Programs/Python/Python310/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "C:/Users/test/AppData/Local/Programs/Python/Python310"
WSGIPythonPath "C:/Users/test/AppData/Local/Programs/Python/Python310/lib/site-packages/"
<VirtualHost *:81>
WSGIScriptAlias / "D:/django_project/gis_api/gis_api/gis_api/wsgi.py"
<Directory "D:/django_project/gis_api/gis_api/gis_api/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "D:/django_project/gis_api/gis_api/static/"
<Directory "D:/django_project/gis_api/gis_api/static/">
Require all granted
</Directory>
Alias /media "D:/django_project/gis_api/gis_api/media/"
<Directory "D:/django_project/gis_api/gis_api/media/">
Require all granted
</Directory>
</VirtualHost>
error.log
mod_wsgi (pid=20212): Failed to exec Python script file 'D:/django_project/gis_api/gis_api/gis_api/wsgi.py'., referer: http://127.0.0.1:81/
mod_wsgi (pid=20212): Exception occurred processing WSGI script 'D:/django_project/gis_api/gis_api/gis_api/wsgi.py'., referer: http://127.0.0.1:81/
Traceback (most recent call last):\r, referer: http://127.0.0.1:81/
ModuleNotFoundError: No module named 'gis_api'\r, referer: http://127.0.0.1:81/
version :
Django 4.1.1
mod-wsgi 4.9.4
os window 10
I have try to all solution. But getting error. I am beginner to deployment in django apache. Pl guide me best path of deployment.
my project structure
WSGIPythonPath needs to point to your app directory like
WSGIPythonPath "D:/django_project/gis_api"
For the moment you are twice adding the environment path (WSGIPythonHome and ...Path) to the python search path but not your apps directory.
I have a config like this :
CentOS 7 - Varnish ( cache server ) / Nginx ( reverse proxy ) / Apache
And it's my Django configuration :
WSGISocketPrefix /var/run/wsgi
<VirtualHost ip:8181>
ServerName domain.ir
ServerAlias www.domain.ir
ServerAdmin info#domain.ir
DocumentRoot /var/www/DjangoProject
UseCanonicalName On
ScriptAlias /cgi-bin/ /var/www/DjangoProject/cgi-bin/
<Directory /var/www/DjangoProject/DjangoProject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /statics/ "/var/www/DjangoProject/statics/"
<Directory "/var/www/DjangoProject/statics">
Require all granted
</Directory>
WSGIDaemonProcess DjangoProject python-path=/usr/lib/python3.4/site-packages python-home=/var/www/DjangoProject user=djangouser socket-user=djangouser
WSGIProcessGroup DjangoProject
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/DjangoProject/DjangoProject/wsgi.py
ErrorLog /var/log/apache/django-error.log
</VirtualHost>
When i want to open my website there is a permission denied error in apache log :
[wsgi:error] [pid 2131:tid 140344565954304] (13)Permission denied: [client 77.104.92.126:38982] mod_wsgi (pid=2131): Unable to connect to WSGI daemon process 'TiTar_API' on '/var/run/wsgi.2128.0.1.sock' as user with uid=99.
I know that uid=99 is nobody user. What's going on here? Why this user want to connect WSGI socket? What is the purpose of user and socket-user attributes in WSGIDaemonProcess?
Edit : I saw other questions too, but i think there is another problem ( nobody user )
Django-WSGI setup causing permission denied issues on CentOS 7
Django + Apache + mod_wsgi permission denied
https://serverfault.com/questions/357804/apache2-mod-wsgi-django-named-virtual-servers
I want to configure my Debian server to provide my Django application. Everything is working fine but my Apache2 is blocking the access to my admin site.
So when I am trying to access www.mydomain.com/admin the Apache2 says that I don't have permission to access that site. I can't get why.
Alias /static /etc/website/portal/static
Alias /media /etc/website/portal/static/media
Alias /admin /etc/website/portal/static/admin
<Directory /etc/website/portal/static/admin >
Require all granted
</Directory>
<Directory /etc/website/portal/static>
Require all granted
</Directory>
<Directory /etc/website/portal/static/media>
Require all granted
</Directory>
<Directory /etc/website/portal/Portal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess portal python-home=/etc/website/ python-path=/etc/website/portal
WSGIProcessGroup portal
WSGIScriptAlias / /etc/website/portal/Portal/wsgi.py
The structure of my project on the server:
-etc
---website 'that is my virtualenv'
-----portal 'my project folder'
-------manage.py
-------templates
-------Portal 'main project'
-------SomeApp
-------static
----------admin
-------------'files of admin'
----------img
----------media
----------static
I thought that I gave access with configuring following in the admin:
Alias /admin /etc/website/portal/static/admin
<Directory /etc/website/portal/static/admin >
Require all granted
</Directory>
I also changed the permissions on the admin folder with chmod 777 and chown :www-data but it is still not working.
I don't know if it is relevant but I use a MySQL database.
Thank you for your help ! If some information are missing just let me know it.
FYI: I restarted Apache several times ;)
EDIT: Apache error.log
[Sat Feb 03 12:57:46.159991 2018] [autoindex:error] [pid 1648:tid 140319177287424] [client 188.97.14.161:59095] AH01276:
Cannot serve directory /etc/website/portal/static/admin/:
No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found,
and server-generated directory index forbidden by Options directive
I am trying to deploy django project in apache on Mac OSX.
Follow all steps from Deploy Django on Mac OSX
Getting this error in log:
(13)Permission denied: [client ::1:63146] AH00035: access to / denied (filesystem path '/Users/nitinsolanki/Documents/virtual_environment') because search permissions are missing on a component of the path
Set include /private/etc/apache2/extra/vhosts/localhost.conf in /etc/apache2/extra/httpd-vhosts.conf
Create a file - localhost.conf inside /etc/apache2/extra/vhosts/
<VirtualHost *:80>
ServerName localhost
# Static files
DocumentRoot "/Users/nitinsolanki/Documents/virtual_environment/test/"
ErrorLog "/Users/nitinsolanki/Documents/virtual_environment/test/error.log"
CustomLog "/Users/nitinsolanki/Documents/virtual_environment/test/access.log" common
Alias /static/ /Users/nitinsolanki/Documents/virtual_environment/test/static
<Directory /Users/nitinsolanki/Documents/virtual_environment/test/static>
Order deny,allow
Allow from all
</Directory>
<Directory /Users/nitinsolanki/Documents/virtual_environment/test/myproject>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess test python-path=/Users/nitinsolanki/Documents/virtual_environment/test:/Users/nitinsolanki/Documents/virtual_environment/test/virtual_test/lib/python2.7/site-packages
WSGIProcessGroup test
WSGIScriptAlias / /Users/nitinsolanki/Documents/virtual_environment/test/myproject/wsgi.py
</VirtualHost>
How can overcome the issue of Permission ? Even I set the permission to django-project( test )
I'm trying to deploy Django to apache but can't get it to serve my static admin files. It seems to be looking for them under /var/www/static and I can't seem to be able to change that.
The admin site seem to be working except for styling. I get a title and a log in form. My django app is working too. It's the static files for the admin that aren't served.
Using Django 1.4.1.
The files are under /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static and linked to from /home/dutt/vaccapp/backend/static/admin.
The apache error log says this
[Sun Sep 30 10:57:20 2012] [error] [client 192.168.1.10] File does not exist: /var/www/home, referer: http://dathui.example.com/vaccapp/admin/
[Sun Sep 30 10:57:20 2012] [error] [client 192.168.1.10] File does not exist: /var/www/home, referer: http://dathui.example.com/vaccapp/admin/
But I'm not sure how to change it.
In my django site config I have
<VirtualHost *:80>
ServerAdmin me#host.com
ServerRoot "/home/dutt/vaccapp"
DocumentRoot "/home/dutt/vaccapp"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/dutt/vaccapp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /static/ "/home/dutt/vaccapp/backend/static/"
<Directory "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
ServerRoot is not set in apache2.conf.
From my settings.py
STATIC_ROOT = '/home/dutt/vaccapp/backend/'
STATIC_URL = '/static/'
Nothing added to STATICFILES_DIRS.
This is added to my apache2.conf
WSGIScriptAlias /vaccapp /home/dutt/vaccapp/backend/wsgi.py
WSGIPythonPath /home/dutt/vaccapp
<Directory /home/dutt/vaccapp>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
ADMIN_MEDIA_PREFIX is set by default to /static/admin/ # Deprecated in Django 1.4 (now using STATIC_URL + 'admin/'. The result is the same.
Here's the fixes to the apache config:
Alias /static/admin "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static"
Alias /static "/home/dutt/vaccapp/backend/static"
<Directory "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
And the WsgiScriptAlias had to be moved from the main apache config into the VirtualHost.
After a long discussion we found the problem was that Django did not install the admin static properly ... they were symlinked to eachother (very weird). A Django reinstall fixed it and it worked fine now.
My low reputation forces me to write a whole answer to add a small detail to Igor's answer.
I simply added the apache config part to my configuration, but it was not sufficient. I had to change:
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static"
to
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/admin"
both in the first Alias and in the <Directory> directive.
Just like Blazor I had to use a small variation of the original. My setup includes graphite-web, which is using django admin. I'm just posting it for reference.
My apache's virtual host:
<VirtualHost *:80>
ServerName graphite.myhost.com
Redirect permanent / https://graphite.myhost.com/
</VirtualHost>
<VirtualHost *:443>
ServerName graphite.myhost.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/graphite.cert
SSLCertificateKeyFile /etc/apache2/ssl/ssl_graphite.key
SSLStrictSNIVHostCheck on
WSGIDaemonProcess _graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 user=_graphite group=_graphite
WSGIProcessGroup _graphite
WSGIImportScript /usr/share/graphite-web/graphite.wsgi process-group=_graphite application-group=%{GLOBAL}
WSGIScriptAlias / /usr/share/graphite-web/graphite.wsgi
AliasMatch ^/admin/(.*)static/admin(.*)$ /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/$2
<Directory "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/">
Order allow,deny
Allow from all
</Directory>
Alias /content/ /usr/share/graphite-web/static/
<Location "/content/">
SetHandler None
</Location>
<Location "/">
Order allow,deny
allow from all
AuthType Basic
AuthName "Restricted Zone"
AuthBasicProvider wsgi
WSGIAuthUserScript /var/www/django_auth.wsgi
Require valid-user
</Location>
ErrorLog ${APACHE_LOG_DIR}/graphite-web_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/graphite-web_access.log combined
</VirtualHost>
I also added STATIC_URL = 'static/' just to make sure I didn't have any issues with the regex.
Try using next
python manage.py collectstatic
The staticfiles app - Django documentation
I got similar problem when running Django + Apache, the Django admin site misses all styling. This is how I solved it:
apache conf: httpd-app.conf
Alias /static "/...path/to/your/django.../site-packages/django/contrib/admin/static"
<Directory "/...path/to/your/django.../site-packages/django/contrib/admin/static">
Require all granted
</Directory>
The /...path/to/your/django.../ above, you can find it by pip show django