I've been trying out quite a many things to the level of high frustration when trying to get Flask run with Apache + mod_wsgi.
Basically I've done the following tutorials:
http://flask.pocoo.org/docs/deploying/mod_wsgi/#installing-mod-wsgi
http://www.lonesomedev.com/?p=169
But on browser I'm getting the following error:
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
And in Apache error.log the following:
[Fri May 03 17:17:06 2013] [error] [client ::1] client denied by server configuration: /home/user1/Develop/flask_dbadmin.wsgi
I'm running OpenSuse 11.4.
If you tried things mentioned Apache2: 'AH01630: client denied by server configuration' here and it still doesn't work chances are your wsgi script alias path is outside path mentioned in <Directory> block.
You need a <Directory> or <Location> block for every Alias.
So for example,
for
WSGIScriptAlias / /home/stark/FlaskApp/flaskapp.wsgi
you would need
<Directory /home/stark/FlaskApp>
Require all granted
</Directory>
It sounds like Apache doesn't have access to the object in question. Make sure you have an account set up for this specific reason and give the files access this account. Then use chown to set the access to these files for that user. In a development environment that can be for example the Apache account.
chown -R wwwrun:www /home/user1/Develop/
Or you could give everyone access, but I wouldn't recommend this.
chmod 777 -R /home/user1/Develop/
If that doesn't work you may need to manually allow access to the wsgi files in your apache config.
It should look something like this.
WSGIDaemonProcess flask_dbadmin user=wwwrun group=www threads=5
<VirtualHost *:80>
........
<Directory /home/user1/Develop/ >
Order allow,deny
Allow from all
</Directory>
<Files flask_dbadmin.wsgi>
Order allow,deny
Allow from all
</Files>
</VirtualHost>
Related
I have a problem. I'm creating a server where I will host a Django project and also PGAdmin4. I configured PGAdmin to run through apache2 and WSGI with a Python 3.8 virtual environment. It was working perfectly before I set up the Django project. at the ip/pgadmin. As soon as i manage to host the Django on the virtual host. The pgadmin started not to work.
When trying to enter the "ip/pgadmin" while the django webserver is not at the root at the WSGIScriptAlias i receive this page.
Not Found
The requested URL was not found on this server.
Apache/2.4.41 (Ubuntu) Server at 192.168.0.10 Port 80
and the following log error. The pgadmin4 is installed withing the same virtualenv that runs the django project but as they are daemons thats not a problem. So i do not see why is searching under "/var/www/acas_webserver/pgadmin/"
[Tue Mar 16 00:54:22.633470 2021] [core:info] [pid 26119:tid 140348751849216] [client 192.168.0.5:63072] AH00128: File does not exist: /var/www/acas_webserver/pgadmin/
But when i place the django project at the root of the WSGIScriptAlias i reacieve this page but no log info to know what happened.
Not Found
The requested resource was not found on this server.
I'm trying to get both of them work alone and having my django at the root of the directories of the apache2 virtual hosts + wsgi. I cannot fint whats the problem an its been countless hours without figuring it out. where are the virtual hosts configurations
#django project
<VirtualHost *:80>
ServerAdmin lemanuel.colon#upr.edu
ServerName 192.168.0.10
DocumentRoot /var/www/acas_webserver
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel info
Alias /static /var/www/acas_webserver/static
<Directory /var/www/acas_webserver/static>
Require all granted
</Directory>
Alias /media /var/www/acas_webserver/media
<Directory /var/www/acas_webserver/media>
Require all granted
</Directory>
<Directory /var/www/acas_webserver/adapts>
<Files wsgi.py>
Require all granted
</Files>
Require all granted
</Directory>
WSGIDaemonProcess acas_app python-path=/var/www/acas_webserver python-home=/var/www/acas_webserver/my_venv
WSGIProcessGroup acas_app
WSGIScriptAlias / /var/www/acas_webserver/adapts/wsgi.py
WSGIApplicationGroup %{GLOBAL}
</VirtualHost>
#Pgadming
<VirtualHost *:80>
ServerName 192.168.0.10
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/pgadmin-error.log
CustomLog ${APACHE_LOG_DIR}/pgadmin-access.log combined
DocumentRoot /var/www/acas_webserver/my_venv/lib/python3.8/site-packages/pgadmin4/
LoadModule wsgi_module modules/mod_wsgi.so
WSGIDaemonProcess pgadmin processes=1 threads=25 python-home=/var/www/acas_webserver/my_venv
WSGIScriptAlias /pgadmin /var/www/acas_webserver/my_venv/lib/python3.8/site-packages/pgadmin4/pgAdmin4.wsgi
<Directory /var/www/acas_webserver/my_venv/lib/python3.8/site-packages/pgadmin4/>
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>
I just want to get them work to continue on with this projects and its been several days of headaches. Can someone be of help here? If anything is need im happy to provide. Plz help.
UPDATE:
The problem is all coming up once I enable the django webserver. As soon as i turn of my django webserver on Apache2, i can access my pgadmin page, but as soon as I turn on my django webserver on Apache2, the pgadmin again is unreachable.
I have looked at your configs ( e.x apache ) and seem fine.
I think, there are many possible ways to solve your problem.
The first way would be using some docker container that fits your needs. if you don't know about it just "GOOGLE: docker Django Postgres apache " and read the top links.
Search for it and there are many results already there. After that, you can run your project probably. I don't want to go deep into docker but surely would solve your problem.
Second, Check and monitor your services, ports, and permissions. If they are not in right place, maybe your server ports are busy or you should restart the services. (as you said worked fine before the Django installation, this idea has a low chance to solve the problem)
Furthermore, You should deploy your Django project in the right folder. the differences between those logs are rational. root folder probably is under a read-only mode.
you have mentioned that you have to work on this project and it's been several days of headaches. My first question is why do you focus on server deployment rather than coding? You can easily run Postgre, WSGI, and Django without any headache ! ( developing environment)
and pgadmin isn't a necessary tool. Also, if it's the problem and you should use it just ignore it and pass it to the final stage which you have done your coding phases. ( seems you stuck in the first place without coding)
I've been trying to deploy a Django app on Ubuntu 18.04 using Apache2 for the past couple of days now, and it still doesn't work.
My apache2 config is:
<VirtualHost *:1337>
<Directory /var/www/LGSM_webpanel/LGSM_webpanel>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/LGSM-error.log
CustomLog ${APACHE_LOG_DIR}/LGSM-access.log combined
WSGIScriptAlias / /var/www/LGSM_webpanel/LGSM_webpanel/wsgi.py
WSGIDaemonProcess LGSM_webpanel python-path=/var/www/LGSM_webpanel
WSGIprocessGroup LGSM_webpanel
DocumentRoot /var/www
</VirtualHost>
However, for some reason, when I access http://localipofthemachine:1337 I just get the google chrome error Connection refused.
Now, the server works when I use manage.py runserver, and I can fully access it, but when I use apache, I just get this error.
The apache logs are also empty by the way.
Thanks in advance for your help
First of all, you need to add Listen 1337 in the virtual host configuration, i.e.
Listen 1337
<VirtualHost *:1337>
# your configuration
# etc
</VirtualHost>
Second, make sure that the apache user www-data can access your webapp files by running chown www-data:www-data -R /var/www/LGSM_webpanel.
I'm trying to set up an Apache2/Django server on Ubuntu 18.04 x64 Digital Ocean droplet. I've went through the tutorials but still get an error. I've searched Stackoverflow and other sources for the solution, but still nothing works. Would someone be able to help?
The project is placed in /root/myproject. I use virtualenv that I named myprojectenv. So the python path is correct with /root/myproject/myprojectenv. I'm using Python 3.6 and the version of
/root/myproject/myprojectenv/bin/python is indeed 3.6. I'm using libapache2-mod-wsgi-py3.
I have chown'ed the whole /root/myproject folder to 'www-data' and chmod'ed to 664 the sqlite.db file in accordance with DigitalOcean's tutorial.
The content of my /etc/apache2/sites-available/000-default.conf file is (comments deleted):
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /root/myproject
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static/ /root/myproject/static/
<Directory /root/myproject/static>
Require all granted
</Directory>
<Directory /root/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/root/myproject/myprojectenv python-path=/root/myproject
WSGIProcessGroup myproject
WSGIScriptAlias / /root/myproject/myproject/wsgi.py process-group=myproject
</VirtualHost>
The content of /root/myproject/myproject/settings.py is:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '[SOME STRING]'
DEBUG = True
ALLOWED_HOSTS = ['[IP Address as a string]']
...
The error I get by trying to access the page via browser:
Forbidden You don't have permission to access / on this server.
Apache/2.4.29 (Ubuntu) Server at [IP ADDRESS] Port 80
The error log from /var/log/apache2/error.log
[Wed May 16 19:55:47.012027 2018] [wsgi:warn] [pid 3565:tid 140254930643904] (13)Permission denied: mod_wsgi (pid=3565): Unable to stat Python home /root/myproject/myprojectenv. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
The problem seems to be with apache being unable to run python.
Thanks in advance. Happy to add further information if needed.
Best regards
Saalim
I've successfully deployed my Django webapp on OS X Server 10.9 using the config .plist and extra httpd.conf using the built-in server manager.
(as per: How does one deploy a django application on OS X Server?, Deploying Django on OS 10.9 Server)
Now I'm trying to get it running using mod_wsgi's daemon mode, rather than the default embedded mode.
So I went back to bare basics: running the included OS X Server mod_wsgi tester bare Python script, which has a httpd conf file with the single line:
WSGIScriptAlias /wsgi /Library/Server/Web/Data/WebApps/hello.wsgi
Changed it to:
WSGIDaemonProcess wsgi_test processes=2 threads=15
WSGIProcessGroup wsgi_test
WSGIScriptAlias /wsgi /Library/Server/Web/Data/WebApps/hello.wsgi
However, it fails when attempting to turn the site back on, with the following message to the apache error log:
[Tue Sep 09 11:56:08 2014] [notice] caught SIGTERM, shutting down
[Tue Sep 09 11:56:12 2014] [crit] (17)File exists: mod_rewrite: Parent could not create RewriteLock file /var/log/apache2/rewrite.lock
Configuration Failed
Then the site 'unticks' itself in the Server admin. I've checked, and the rewrite.lock file doesn't exist when the webserver is turned off.
Should it work? My other concern is whether daemon mode supported out of the box, or I need a new mod_wsgi.
I had a similar error "caught SIGTERM, shutting down" in the Apache error logs on Yosemite. Unfortunately, I can't speak to the mod_rewrite issue.
The SIGTERM seems to occur when the python-path is not set in the WSGIDaemonProcess directive.
Here's a configuration that worked for me for a basic Django app on OSX:
WSGIDaemonProcess myapp processes=2 threads=15 python-path=/path/to/django/app/
WSGIProcessGroup myapp
WSGIScriptAlias /myapp /path/to/django/app/wsgi.py process-group=myapp
<Directory "/path/to/django/app/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
I'm not sure if the <Directory> config is required or not. However, setting the python-path in WSGIDaemonProcess solved the SIGTERM issue for me.
Hope this helps.
I have a micro instance on EC2 with Django installed there. I've also installed mod-WSGI, PostgreSQL, etc following several tutorials.
Finally, I pulled my project from bitbucket and started Apache on my EC2. Unfortunately, the only thing I have is the default Apache page and I've already spent a day and night reading and trying to figure out what am I doing wrong.
my_project is in /home/ubuntu dir. In it's folder I have wsgi.py file:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
This is my .conf file stored in /etc/apache2/httpd.conf:
Listen 80
NameVirtualHost *:80
WSGIPythonPath /home/ubuntu/my_project/
<VirtualHost *:80>
DocumentRoot /home/ubuntu/my_project
ServerName www.ec2-54-***-104-**.us-west-2.compute.amazonaws.com
ServerAlias ec2-54-***-104-**.us-west-2.compute.amazonaws.com
ErrorLog /home/ubuntu/my_project/apache/error_log
CustomLog /home/ubuntu/my_project/access_log_common
WSGIScriptAlias / /home/ubuntu/my_project/wsgi.py
Alias /static/ /home/ubuntu/my_project/static/
<Directory /home/ubuntu/my_project/static>
Require all granted
</Directory>
<Directory /home/ubuntu/my_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
When I'm trying to
/etc/init.d/apache2 stop
and instead:
python manage.py runserver 0.0.0.0:80
It works fine and I'm able to connect to my app from a browser with IP as URL.
It gives me understanding that the setting.py file is fine (am I right?) and the problem is or in wsgi.py or httpd.conf.
When I stop my development server and start Apache again, I get the default Apache page. Can you help me please to find what's wrong with my files?
Permissions for apache:
ubuntu#ip-172-**-**-69:~$ ls -ld my_project/
drwxr-xr-x 10 www-data www-data 4096 May 26 19:51 project/
You normally shouldn't use an IP address for ServerName, it has to be the hostname (FQDN) that the site is accessed as.
You are missing a WSGIDaemonProcess directive to correspond to your use of WSGIProcessGroup.
It is bad security practice to set DocumentRoot to be where your source code for your application is.
Finally, stuff under a users home directory is not usually accessible to the user that Apache runs as.
Suggest go back and review the mod_wsgi deployment documentation on the Django site again for a start.