Error 403: Forbidden You don't have permission to access / on this server with apache, mod-wsgi and django - 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

Related

Mod_wsgi error (Getting error message in error_log)

Getting error message in error_log
[Wed May 17 16:02:05.624941 2017] [:error] [pid 28655] [remote 10.10.10.48:148] mod_wsgi (pid=28655): Exception occurred processing WSGI script '/usr/share/ipa/wsgi.py'.
[Wed May 17 16:02:05.625006 2017] [:error] [pid 28655] [remote 10.10.10.48:148] Traceback (most recent call last):
###wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AdminPanel.settings')
application = get_wsgi_application()
###xyz.conf
<VirtualHost *:80>
ServerAdmin admin#xyz.com
ServerName xyz.com
ServerAlias www.xyz.com
DocumentRoot /home/abc/Disk1/andew/xyz/xyz
ErrorLog /home/abc/Disk1/andew/xyz/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static/admin/ /home/abc/Disk1/andew/xyz/xyz/static/admin/
<Directory "/home/abc/Disk1/andew/xyz/xyz/static/admin">
Require all granted
</Directory>
Alias /static/ /home/abc/Disk1/andew/xyz/xyz/static/
<Directory /home/abc/Disk1/andew/xyz/xyz/static>
Require all granted
</Directory>
Alias /media/ /home/abc/Disk1/andew/xyz/xyz/media/
<Directory /home/abc/Disk1/andew/xyz/xyz/media>
Require all granted
</Directory>
<Directory /home/abc/Disk1/andew/xyz/xyz/AdminPanel>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess xyz.com python-path=/home/abc/Disk1/andew/xyz/xyz python-home=/home/abc/Disk1/andew/xyz/xyz/env
WSGIApplicationGroup %{GLOBAL}
WSGIProcessGroup xyz.com
WSGIScriptAlias / /home/abc/Disk1/andew/xyz/xyz/AdminPanel/wsgi.py
</VirtualHost>

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!

Forbidden 403 You don't have permission to access this resource. (mod_wsgi, wamp, apache2.4, django) on windows

i have installed everything properly and gone through all solutions related to this subject but still error remains, I'm new to Django and i would really appreciate your help
I get this error in my error log file:
[Fri Feb 14 21:52:16.916422 2020] [authz_core:error] [pid 4288:tid 1252] [client ::1:51391] AH01630: client denied by server configuration: E:/AppSource/eCommerce/src/ecommerce/wsgi_windows.py
and when i try to reach 127.0.0.1:80 i get: Forbidden 403
and this is my wsgi_windows.py configuration:
activate_this = 'CE:/AppSource/eCommerce/Scripts/activate_this.py'
exec(open(activate_this).read(),dict(__file__=activate_this))
import os
import sys
import site
from django.core.wsgi import get_wsgi_application
site.addsitedir("C:/Python37/Lib/site-packages")
sys.path.append('E:/AppSource/eCommerce')
sys.path.append('E:/AppSource/eCommerce/src')
sys.path.append('E:/AppSource/eCommerce/src/ecommerce')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ecommerce.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ecommerce.settings")
application = get_wsgi_application()
and this is hhtpd-vhosts.conf configuration:
<VirtualHost *:80>
ServerName localhost
WSGIPassAuthorization On
ErrorLog "E:/appSource/eCommerce/eCommerce.error.log"
CustomLog "E:/appSource/eCommerce/eCommerce.access.log" combined
WSGIScriptAlias / "E:/appSource/eCommerce/src/ecommerce/wsgi_windows.py"
<Directory "E:/appSource/eCommerc/src/ecommerce/">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
Alias /static "E:/appSource/eCommerce/static_cdn/static_root"
<Directory "E:/appSource/eCommerce/static_cdn/static_root">
Require all granted
</Directory>
Alias /media "E:/appSource/eCommerce/static_cdn/media_root"
<Directory "E:/appSource/eCommerce/static_cdn/media_root">
Require all granted
</Directory>
</VirtualHost>
i have tried everything that i know
Please help to solve this
Thanks
I think the easiest way to achieve your goal is to change the port number of apache and start the apache again.

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

End of script output before headers: wsgi.py

I am trying to install my django project with Apache, mod_wsgi and python3. but Apache still gives this error:
Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
assert tlock is not None
AssertionError:
End of script output before headers: wsgi.py
I lost two days trying to fix this problem, I know that this error can be produced by several reasons but I not find where the problem.
Here the wsgi.py content:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import site, sys
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
sys.path.append(path)
sys.path.append('/var/www/myproject/myproject_env/bin/python3.4/dist-packages')
site.addsitedir('/var/www/myproject/myproject_env/bin/python3.4/dist-packages')
os.environ["DJANGO_SETTINGS_MODULE"] = "myproject.settings"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
The Apache configuration is as follows:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www
Alias /static/ /var/www/myproject/static/
Alias /static/admin/ /var/www/myproject/static/admin/
Alias /uploads/ /var/www/myproject/uploads/
WSGIDaemonProcess myproject lang='fr_FR.UTF-8' locale='fr_FR.UTF-8' python-path=/var/www/myproject:/var/www/myproject/myproject_env/bin/python3.4/dist-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /var/www/myproject/myproject/wsgi.py
WSGIApplicationGroup %{GLOBAL}
<Directory "/var/www/myproject/myproject/">
Require all granted
</Directory>
<Directory "/var/www/myproject/myproject/wsgi.py">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
<Directory /static/admin/>
Require all granted
</Directory>
<Location "/uploads/">
SetHandler None
</Location>
ErrorLog /var/log/apache2/myproject.log
CustomLog /var/log/apache2/myproject.access.log combined
</VirtualHost>
Please anyone helps me fix this?
Solved: I changed the location of my Django project to another folder in a new linux account. I think (and I'm not really sure) the error occurred because /var/www contains another python project using cgi-bin, this maybe creates conflict with my Django project.