I'm trying to run a dash app on our website in a sub-directory. I'm getting a 403 forbidden when trying to access to website.
In the /etc/httpd/logs/ssl_error_logs i get the error:
[Tue Jan 03 13:53:42.973046 2023] [autoindex:error] [pid 50576] [client 134.94.71.5:60550] AH01276: Cannot serve directory /var/www/Typesetter/appname/: No matching DirectoryIndex (index.html,index.php,index.php) found, and server-generated directory index forbidden by Options directive
I think i might have something wrong with either the permissions or the virtualhost setup. But i can't figure out what is going wrong.
I want to run the dashboard on: our-group.our-uni.com/appname
The server is running on centos7.
I got a data folder with biochemical information to provide to the users in /var/www/html/appname/data/ from which i can download the data if i go to our-group.our-uni.com/appname/data/datapoint1.pt.
Since this works and i can also put a index.html/index.php page there without issues, i think my virtualhost setup pointing to WSGI is incorrect?
The error says cannot serve directory /var/www/Typesetter/appname/, but this directory is a symbolic link to /var/www/html/appname/.
The virtualhost file appname.conf located in /etc/httpd/conf.d/:
<VirtualHost *:80>
ServerName our-group.our-uni.com
DocumentRoot /var/www/html/appname
Errorlog /var/www/html/appname/appname-error.log
Alias /topenzyme /var/www/html/topenzmye
WSGIDaemonProcess appname user=apache group=apache threads=5 python-path=/var/www/html/appname/appname-env
WSGIScriptAlias /appname /var/www/html/appname/testapp.wsgi
<Directory /var/www/html/appname>
WSGIProcessGroup appname
WSGIApplicationGroup %{GLOBAL}
Options Indexes FollowSymLinks ExecCGI
Require all granted
</Directory>
</VirtualHost>
I also tried changing to <Directory /var/www/typesetter/appname>, but this also did not work.
The contents of testapp.wsgi in /var/www/html/appname/:
import sys, os
sys.path.insert(0, '/var/www/html/appname')
from testapp import app as application
The contents of testapp.py in /var/www/html/appname/:
from flask import Flask
app = Flask(__name__)
#app.route('/topenzyme/')
def main():
return 'Hello world'
if __name__ == '__main__':
app.run()
Permission setup:
-rwxr-xr-x. 1 apache apache 148 Jan 3 13:37 testapp.py
-rwxr-xr-x. 1 apache apache 100 Jan 3 13:38 testapp.wsgi
I also tried 777, but from what i've read 755 permissions should be sufficient?
If i do httpd -M i get wsgi_module (shared).
The wsgi module should be available.
I tried various virtualhost configs from other posts with similar issues.
I'm really unsure why this is not working.
Is there anything wrong with my configuration settings or could it be something else?
Found out the issue. I was miss-configuring my Apache setup.
As we are already hosting a website on the domain, i should not have tried to setup a virtualhost for the sub-directory. From what i understand now this only works for setting up (sub)domains. With this structure of setting it up the appname.conf file gets added the already existing virtualhost config.
Instead the /etc/httpd/conf.d/appname.conf is now:
WSGIDaemonProcess appname user=apache group=apache threads=5 python-path=/var/www/html/appname/appnameenv
WSGIProcessGroup appname
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias /appname /var/www/html/appname/testapp.wsgi
<Directory /var/www/html/appname>
Options FollowSymLinks
AllowOverride All
Require all granted
allow from all
</Directory>
This corrently links the wsgi application to my sub-directory location i wanted (our-group.our-uni.com/appname)
Related
I have a Django app which is deployed in local network using Apache + mod_wsgi under Windows. When I run python manage.py runserver, everything works fine. But when I start the Apache Service, I cannot access the app. The only response I get from the access.log is the error code 408. Below is my httpd.conf:
LoadFile "c:/users/felix/appdata/local/programs/python/python37/python37.dll"
LoadModule wsgi_module "c:/users/felix/appdata/local/programs/python/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/users/felix/appdata/local/programs/python/python37"
ServerName localhost
WSGIScriptAlias / "D:/dev/test_server/django/django/wsgi_windows.py"
Listen 8000
<VirtualHost *:8000>
WSGIPassAuthorization On
ErrorLog "logs/django.error.log"
CustomLog "logs/django.access.log" combined
Alias /static "D:/dev/test_server/staticfiles"
<Directory "D:/dev/test_server/staticfiles">
Require all granted
</Directory>
<Directory "D:/dev/test_server/django/django">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And below is the wsgi_windows.py file:
# Activate the virtualenv
activate_this = 'D:/dev/test_server/.venv/Scripts/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))
import os # noqa
import sys # noqa
import site # noqa
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('D:/dev/test_server/.venv/Lib/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('D:/dev/test_server/django')
sys.path.append('D:/dev/test_server/django/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django.settings")
from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application()
I'd appreciate any ideas or hints on the issue.
start apache at command line with 'httpd' and look for error messages. If Apache has a problem at startup there is no message in the log files.
check error.log
You can place 'print('xyz') even in the settings.py and elsewhere and this way by checking error.log see how your app is setup and how far a request is processed. If your app get stuck somewhere like this you find the code where it is stuck
I have the same error after install scipy library and use it in some scrip in django. I found that some libraries like "numpy" and "scipy" only work in the Python main interpreter and you have to force the WSGI to run in the global app group to run it. Adding this line in my conf file work for me.
WSGIApplicationGroup %{GLOBAL}
I'm running Django 2.0.4 with mod_wsgi 4.5.20.
I'm getting an error when I try to deploy a site to our dev environment at /parature. What's weird is that the site deployed at the root of the VirtualHost is responding as normal:
[Tue Apr 10 13:34:08.998704 2018] [wsgi:error] [pid 65245] [client xx.yy.zz:65390] Timeout when reading response headers from daemon process 'parature-develop-https': /var/django/html/parature-develop/config/wsgi.py
I can run the site via runserver with the virtualenv activated. It shouldn't be timing out, as I'm just trying to bring up the Django admin site.
<VirtualHost *:443>
SSLEngine On
ServerName wrds-pub1-dev.example.com
ErrorLog "|/usr/sbin/cronolog /var/log/httpd/errorlog/%Y/%Y-%m-wrds-pub1-dev-error.log"
LogLevel info
WSGIApplicationGroup %{GLOBAL}
# The site I'm adding, which isn't working
WSGIDaemonProcess parature-develop-https python-home=/var/django/virtualenvs/parature-develop request-timeout=600
WSGIProcessGroup parature-develop-https
WSGIScriptAlias /parature /var/django/html/parature-develop/config/wsgi.py process-group=parature-develop-https
<Directory /var/django/html/parature-develop/config>
Require all granted
</Directory>
Alias /parature/static/ /var/django/html/parature-develop/static/
<Directory /var/django/html/parature-develop/static>
Require all granted
</Directory>
# The site which has been and continues to work
WSGIDaemonProcess django-wrds-dev-https python-home=/var/django/virtualenvs/django-wrds-dev request-timeout=600
WSGIScriptAlias / /var/django/html/django-wrds-dev/config/wsgi.py process-group=django-wrds-dev-https
<Directory /var/django/html/django-wrds-dev/config>
Require all granted
</Directory>
Alias /static/ /var/django/html/django-wrds-dev/static/
<Directory /var/django/html/django-wrds-dev/static>
Require all granted
</Directory>
Alias /media/ /var/media/wrds-www/
<Directory /var/media/wrds-www>
Require all granted
</Directory>
</VirtualHost>
I feel like I'm missing something obvious, but can't see it. I've got a similar configuration in another VirtualHost with multiple Django projects under the same domain, and that is working fine, as long as the root site comes last.
The wsgi.py is almost exactly the same as the site that is working as well:
import os, sys, logging
from socket import gethostname
from django.core.wsgi import get_wsgi_application
# Since this powers Apache, let's route Python errors to the Apache
# log rather than STDOUT, where they'll never be seen.
logging.basicConfig(stream=sys.stderr)
# Figure out where we're at, and add the parent to the path
sys.path.append(os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]))
# wrds-pub1-dev server
if 'wrds-pub1-dev' in gethostname():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
# wrds-pub* production servers.
elif 'wrds-pub' in gethostname():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
# else use dev settings.
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_wsgi_application()
Any ideas?
I figured it out - our dev server (since there's never a good time for a rebuild) is our only non-Ansiblized server, and still running mod_wsgi built against Python 3.5. The virtualenv was built against Python 3.6.
I rebuilt the virtualenv against Python 3.5, and everything works. Hopefully this saves someone hair-pulling in the future!
I've been trying to work out how I'll go about setting up a Django application on production, when it's ready for deployment. I'm using Django v1.11, and my EC2 is running Ubuntu 14.04. I have been attempting to refer to this guide as reference, however it is not specific to Ubuntu, so I've been experiencing a bit of difficulty in this regard. I've referred to several other resources, but much of what is out there seems to be outdated.
I have a host rule set up on my local machine, pointing www.example.com to my EC2 instance's public IP address.
I have a virtualenv set up which lives in /home/django/example.com/ENV. My Django project lives in /home/django/example.com directly. The project name is mysite, and was generated using django-admin startproject mysite, thus it has the default wsgi.py file inside the /home/django/example.com/mysite directory. The contents of wsgi.py look like:
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
I've tried adding VirtualHost rules such as the following:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
WSGIScriptAlias / /home/django/example.com/mysite/wsgi.py
<Directory "/home/django/example.com/mysite">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Similarly, I've tried adding:
Include /etc/apache2/httpd.conf
to /etc/apache/apache2.conf and chucking the following:
WSGIScriptAlias / /home/django/example.com/mysite/wsgi.py
WSGIPythonHome /home/django/example.com/ENV
WSGIPythonPath /home/django/example.com
<Directory /home/django/example.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
into httpd.conf.
In either case, I've restarted the Apache server directly afterwards.
I'm not getting any further than hitting "500 Internal Server Error" or hitting an "ERR_EMPTY_RESPONSE".
Anyone able to shed some light around a) where I'm going wrong, b) where I can refer to for up-to-date instructions, or c) how I can troubleshoot this?
After a lot of troubleshooting, and consulting with the resource mentioned in Graham's comment, here's what I established was required in my VirtualHost:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Alias /static /home/django/example.com/static
<Directory /home/django/example.com/static>
Require all granted
</Directory>
WSGIDaemonProcess mysite python-path=/home/django/example.com:/home/django/ENV/lib/python3.4/site-packages
WSGIProcessGroup mysite
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /home/django/example.com/mysite/wsgi.py
<Directory /home/django/example.com/mysite>
Require all granted
</Directory>
</VirtualHost>
and here are the contents of wsgi.py that I settled on:
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os, sys
from django.core.wsgi import get_wsgi_application
path = '/home/django/example.com'
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
And it is also worth noting (simply because it wasn't immediately obvious to me) that it is necessary to specify:
STATIC_ROOT = '/home/django/example.com/static'
in settings.py, and to run python manage.py collectstatic to collect static files from all applications into said STATIC_ROOT.
I hope this helps somebody else, in future!
I am new to working with apache and mod_wsgi. But I do have little experience in django, so from some tutorials I tried to run django app through apache webserver using mod_wsgi.
I created mysite in /var/www/
then in mysite/application I created application.wsgi ...
import os
import sys
sys.path.append('/var/www/mysite/application')
os.environ['PYTHON_EGG_CACHE'] = '/var/www/mysite/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
and in /etc/httpd/sites-available I created file named mysite.conf ...
<VirtualHost *:80>
ServerName mysite.com
ServerAdmin id#somewhere.com
ServerAlias mysite.com
DocumentRoot /var/www/mysite/
<Directory /var/www/mysite>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</Directory>
WSGIDaemonProcess mysite processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup mysite
</Virtualhost>
Then I ran a2ensite mysite.conf, didn't showed any error.
Then in /etc/httpd/hosts/ I added one line my-ipddress mysite.com
I gave permission chmod 777 to all the above files and to folder /var/www/mysite. Now when I open mysite.com on browser I see apahce's default page nothing from django.
I am using fedora 21.
You haven't put in anything in that configuration to serve your Django site via WSGI: you're missing the WSGIScriptAlias line (see the documentation:
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Note that you shouldn't really be putting things in /var/www; and also you shouldn't need to create your own WSGI file, Django creates one for you when you create a project.
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.