Django & WSGI - permission denied - django

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

Related

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

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!

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

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

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

How to configure apache 2.4 VirtualHost with wordpress and django wsgi on debian?

I want to add a wordpress app at blog.mydomain.com but I already have a Django app at mydomain.com running with wsgi in deamon mode.
I work on a Linux server (debian) with apache2.4.10 and PHP 5.6
Here is my apache conf for mydomain.com (django.conf):
<VirtualHost 000.000.000.000:443> (my server ip)
ServerName mydomain.com
ServerAlias mydomain.com
ServerAlias www.mydomain.com
SSLEngine On
SSLCertificateFile /pathToSsl/ssl.crt
SSLCertificateKeyFile /pathToSsl/ssl.key
SSLCertificateChainFile /pathToSsl/ssl.pem
SSLVerifyClient None
WSGIDaemonProcess mydomain.com threads=4
WSGIProcessGroup mydomain.com
WSGIScriptAlias /path/to/settings/wsgi.py
# Aliases toward static data
Alias /media /pathToMedia/media/
Alias /static /pathToStatic/static/
Alias /log /var/www/html/
<Directory /path/to/settings>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access-mydomain.com.log combined
ErrorLog ${APACHE_LOG_DIR}/error-mydomain.com.log
ErrorDocument 500 "Oups something goes wrong."
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias mydomain.com
ServerAlias www.mydomain.com
Redirect / https:// mydomain.com/
</VirtualHost>
This one is working perfectly.
And now I add a new configuration for my wordpress blog (wordpress.conf):
<VirtualHost *:80>
ServerName blog.mydomain.com
DocumentRoot "/var/www/html/wordpress"
<Directory /var/www/html/wordpress>
AllowOverride all
Options Indexes FollowSymLinks
Require all granted
</Directory>
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access-blog.fr.log combined
ErrorLog ${APACHE_LOG_DIR}/error-blog.fr.log
</VirtualHost>
The problem is when i try to access to blog.mydomain.com, I am redirected to mydomain.com after few seconds.
At the beginning, I thought that was because my conf wordpress was not found but if I put
Redirect / stackoverflow.com
in wordpress.conf and it's working. So the issue is not here.
I find this in my apache error log for the wordpress blog :
[Mon Oct 24 13:15:55.829675 2016] [wsgi:error] [pid 16958] [client 000.000.000.000:38439] mod_wsgi (pid=16958): Exception occurred processing WSGI script '/path/to/settings/wsgi.py'., referer: http://blog.mydomain.com/
[Mon Oct 24 13:15:55.829844 2016] [wsgi:error] [pid 16958] [client 000.000.000.000:38439] IOError: failed to write data, referer: http://blog.mydomain.com/
In my opinion, the problem come from wsgi, but i don't know why and how to resolve it.
I don't understand why this conf go over wsgi.
I hope you can help me.
Thanks for reading.

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 )