You don't have permission to access admin (Django, wsgi, Apache) - django

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

Related

Stuck on apache2 default page while deploying Django website

I have gone through a few answers on the web and I am still struggling to get past the apache2 default page. The webapp works fine locally and without apache. I am using an AWS EC2 instance for this on an ubuntu machine.
The whole code is hosted in /home/ubuntu/sm on the machine, the venv is in /home/ubuntu/sm/venv and running on the ip addr 3.X.X.212
I've tried adding, editing, removing a few variables, to no avail. I got nothing in the error logs either. The 'gracefully restarting' entries are starting to look narcissistic given how long I've been stuck on this.
apachectl -S produces the following response:
[Tue Nov 05 05:16:52.198045 2019] [alias:warn] [pid 13664:tid 139764718218176] AH00671: The Alias directive in /etc/apache2/sites-enabled/sm.conf at line 33 will probably never match because it overlaps an earlier Alias.
VirtualHost configuration:
*:80 ip-172-*-*-29.ap-southeast-2.compute.internal (/etc/apache2/sites-enabled/sm.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
"sm.conf" is the config file used for this, as below:
ServerAdmin webmaster#localhost
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /robots.txt /home/ubuntu/sm/website/static/robots.txt
Alias /favicon.ico /home/ubuntu/sm/website/static/favicon.ico
Alias /static/ /home/ubuntu/sm/website/static
Alias /static/ /home/ubuntu/sm/media
WSGIDaemonProcess website.net processes=2 threads=15 python-home=/home/ubuntu/sm/venv/lib/python3.6 python-path=/home/ubuntu/sm/
WSGIProcessGroup website.net
WSGIScriptAlias /sm /home/ubuntu/sm/sm/wsgi.py process-group=website.net
<Directory /home/ubuntu/sm/>
AllowOverride all
Require all granted
Options FollowSymlinks
</Directory>
<Directory /home/ubuntu/sm/sm>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/ubuntu/sm/website/static/>
Require all granted
</Directory>
<Directory /home/ubuntu/sm/media>
Require all granted
</Directory>
Comments, concerns, suggestions, critique of shoddy code, all appreciated.

Django & WSGI - permission denied

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

Django (13) Permission denied: AH00035: access to / denied because search permissions are missing on a component of the path on Mac OSX

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 )

Can't get Apache to serve django admin static files

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

Django with Apache and mod_wsgi getting a 403(Forbidden)

I am trying to get a Django app running on Apache with mod_wsgi. I got a 403(Forbidden) for both any file in /static and /(the Django app). The apache user has permission to the wsgi.py and can list /apps/{DIR}/static. I even changed the user and group of all the file/directories in /apps/{DIR}. I can su to the apache user can traverse to wsgi.py. I can manually run apache is debug mode with httpd -X and everything works fine! (I can access the Django app and the static content) But when I run it normally it does not work, I get a 403.
RHEL 6.2,
Python 2.6.6,
Django 1.3,
httpd-2.2.15,
mod_wsgi-3.2
/etc/httpd/conf/httpd.conf:
WSGIScriptAlias / /apps/{DIR}/{APP_NAME}/apache/wsgi.py
WSGIPythonPath /apps/{DIR}/{APP_NAME}
<Directory /apps/{DIR}/{APP_NAME}/apache>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Alias /static /apps/{DIR}/static
<Directory /apps/{DIR}/static>
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
#Options FollowSymLinks
AllowOverride None
</Directory>
error in httpd/error_log
[...] [error] [client x.x.x.x] (13)Permission denied: access to / denied
[...] [error] [client x.x.x.x] (13)Permission denied: Can't open directory for index: /apps/{DIR}/static/
Does anyone have any ideas?
Thanks
Are you running with SELinux enabled?
Are all directories from '/' down to the static media directory readable to Apache user, not just the directory itself?