I have a Django 1.4.5 project called mp which I'm trying to run on my localhost using Apache 2.4. Following the official tutorial for Django with mod_wsgi
(How to use Django with Apache and mod_wsgi) I managed to display my Django page when I visit http://127.0.0.1:8801/.
My project folder mp is located in /opt/masterportal/mp, and the static files are located in /opt/masterportal/mp/mp/static.
This is my masterportal.conf file in /etc/apache2/sites-available:
Listen 8081
<VirtualHost *:8081>
ServerAdmin my#mail.adress
XSendFilePath /opt/masterportal/mp/mp/uploads/
<Files *.*>
XSendFile On
</Files>
WSGIDaemonProcess masterportal python-path=/opt/masterportal/mp:/opt/masterportal/mp/env/dev/lib/python2.7/site-packages
WSGIProcessGroup masterportal
WSGIScriptAlias / /opt/masterportal/mp/mp/apache/wsgi.py
Alias /static /opt/masterportal/mp/mp/static
<Directory /opt/masterportal/mp/mp/static>
Require all granted
</Directory>
<Location />
WSGIProcessGroup masterportal
Require all granted
</Location>
</VirtualHost>
However, the website at http://127.0.0.1:8801 can't find any of the static files. This is odd, because the exact same project works on the server of my university (where I don't have access to the apache configuration). So there must be something wrong with my Apache configuration, but I can't see what. I'm desperate for help.
Some general information: I'm using Django 1.4.5 (because this is the version on the university server), and Apache 2.4. The project runs in a virtualenv located here /opt/masterportal/mp/env. I also tried it with Alias /static/ instead of Alias /static, but that didn't work either. My apache2.conf is still original - I made no changes there.
Edit: Here's my configuration for the site in /etc/apache2/conf-available/:
<Location "/mp/2015/suse">
ProxyPass https://my-computername:8081/
ProxyPassReverse https://my-computername:8081/
RequestHeader set X-FORWARDED-PROTOCOL ssl
RequestHeader set X-FORWARDED-SSL on
</Location>
Try to move the lines
Alias /static /opt/masterportal/mp/mp/static
<Directory /opt/masterportal/mp/mp/static>
Require all granted
</Directory>
before
WSGIDaemonProcess masterportal python-path=/opt/masterportal/mp:/opt/masterportal/mp/env/dev/lib/python2.7/site-packages
WSGIProcessGroup masterportal
WSGIScriptAlias / /opt/masterportal/mp/mp/apache/wsgi.py
because the link with /static/some_static_files... might be forwared to the wsgi app instead of pointing to the static directory.
Related
I deployed a beta version of my django app to DigitalOcean and I am serving it using Apache and WSGI.
Everything works well include static files and 'get' media files(I saved it directly to DB), except uploading files.
It shows 'Permission denied' error, with full directory like '/home/test/project/media/test.jpeg'.
I configured httpd-vhosts like this.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
WSGIScriptAlias / /home/test/project/project/wsgi.py
WSGIDaemonProcess example.com python-home=/home/test/project/.venv python-path=/home/test/project/project
WSGIProcessGroup example.com
Alias /static/ /home/test/project/frontend/build/static/ # react build dir
<Directory /home/test/project/frontend/build/static>
Require all granted
</Directory>
Alias /uploadImg/ /home/test/project/media/
<Directory /home/test/project/media>
Require all granted
</Directory>
<Directory /home/test/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
So httpd is running with daemon, and my directory 'media' is owned by root, 755.
But the directory 'media' is symbolic link dir which located at '/home/test/'
I did many attempts to fix it but nothing works..
Thanks for all the responses
I solved it myself.
My problem was about 'who runs the apache process' and 'who owned the dir'.
It should be same user or group with writing authority.
Hope someone who have problem with this was helpful.
I want to have access to my Django project from anywhere. For this reason, I have a Raspberry Pi with Ubuntu.
If I run the command python manage.py runserver, it runs the project in http://127.0.0.1:8000/ as default. But this is the localhost of my raspberry/ubuntu and what I want is run the project on my laptop. for this reason I change the 127.0.0.1 for the adress of my server http://xxx.xx.xx.x:8000/ and I run it on my browser. THIS FAILS.
Ok, reading some information I see that I have to open a port to access remotely, for this goal I use the ufw library.
I open the 80 port using ufw,
Now if I write http://xxx.xx.xx.x:80 on my browser, don't fail, appear this,
Apache config:
<VirtualHost *:80>
ServerAdmin admin#djangoproject.localhost
ServerName djangoproject.localhost
ServerAlias www.djangoproject.localhost
DocumentRoot /home/smart/IoTIB_Dashboard
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/smart/IoTIB_Dashboard/static
<Directory /home/smart/IoTIB_Dashboard/static>
Require all granted
</Directory>
Alias /static /home/smart/IoTIB_Dashboard/media
<Directory /home/smart/IoTIB_Dashboard/media>
Require all granted
</Directory>
<Directory /home/smart/IoTIB_Dashboard/IoTIB_Dashboard>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess django_project python-path=/home/smart/IoTIB_Dashboard python-home=/home/user/IoTIB_Dashboard/env
WSGIProcessGroup IoTIB_Dashboard
WSGIScriptAlias / /home/smart/IoTIB_Dashboard/IoTIB_Dashboard/wsgi.py
Thus I understand that now is opened.
The problem is that if now I run again my django project as python manage.py runserver 80 and I write again http://xxx.xx.xx.x:80/user_app/login/ in my browser, appears the following,
What I'm doing wrong? I'm newbie and I don't know what I have to do. The objective is to be able to access the project remotely. Can somebody help me?
Thank you very much.
My Flask based web app is ready to go, and I'm currently connecting it up to Apache 2.2.
When I start Apache serving the app from root
WSGIScriptAlias / /var/www/path/to/script.wsgi
everything works as expected. However, I want to serve multiple versions of the WSGI script that will connect to different databases, which means I need to serve each with a unique alias:
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi
...
WSGIScriptAlias /secondscript /var/www/path/to/second/script.wsgi
When I try to access one of these:
www.example.com/firstscript
the WSGI app loads, but all http requests are still routed to the root. What is the best way for me to reroute all http requests to my WSGI app? Here is my apache config:
WSGIPythonHome /usr
WSGIPythonPath /var/www/path/to/first
<VirtualHost *>
WSGIDaemonProcess firstscript user=apache group=apache threads=5 python-path=/lib/python2.7/site-packages
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi
<Directory /var/www/path/to/first>
WSGIProcessGroup %{GLOBAL}
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
EDIT:
I've followed the (much appreciated) recommendations from #grahamdumpleton, which have helped me to clean up my Apache configs, but my http requests continue to be routed to the Apache server's root, rather than the WSGI app. Here's my current config:
WSGIPythonHome /usr
WSGIPythonPath /var/www/path/to/first
<VirtualHost *>
WSGIDaemonProcess firstscript threads=5
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi process-group=firstscript application-group=%{GLOBAL}
<Directory /var/www/path/to/first>
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
I've also tried adding a process group under the directory tag: WSGIProcessGroup firstscript, which also failed to have any impact.
The following should be removed for a start:
WSGIProcessGroup %{GLOBAL}
This is causing everything to be handled in the same Python interpreter, and not even in the daemon process group, so likely they are interfering with each other.
Using:
python-path=/lib/python2.7/site-packages
is also wrong. You don't need that when using system Python, and python-path is wrong way of referring to a virtual environment anyway.
Finally you don't need:
user=apache group=apache
either as defaults to using the Apache user already.
That first change may be enough to get it working as each application will now run in a separate sub interpreter of the daemon process group.
If that doesn't work, you should create more than one daemon process group and delegate each to a separate daemon process group.
That would be done using:
WSGIDaemonProcess firstscript threads=5
WSGIScriptAlias /firstscript /var/www/path/to/first/script.wsgi process-group=firstscript application-group=%{GLOBAL}
WSGIDaemonProcess secondscript threads=5
WSGIScriptAlias /secondscript /var/www/path/to/second/script.wsgi process-group=secondscript application-group=%{GLOBAL}
I follow the tutorial http://docs.django-cms.org/en/develop/introduction/plugins.html, when I install the Polls App as indicated it is visible on 8000 port But not in WSGI/Apache mode (error message no module polls). To see the APP polls I need to copy Polls application files in the default root directory. Idem with the Aldryn Blog News. I guess I have to specify some more PATH in wsgi mode to help Python to find the modules. Where and how to do that in my Virtualenv, to be also effective when I deploy all the stuff on a remote platform ?
Thanks for any help
Thank you for your interest. IMHO I don't think the problem is on APACHE configuration, everything is OK and DjangoCMS works without polls. Herinafter the conf file, the domain is a local virtual one.
DocumentRoot "/var/www/djangocms"
WSGIScriptAlias / /var/www/djangocms/default/wsgi.py
ServerName djangocms.net
Alias /static/ /var/www/djangocms/default/static/
Options +ExecCGI
Order Allow,Deny
Allow from All
ErrorLog "logs/errordjangocms_log"
LogLevel error
Marcel
Here is a working config i use
<VirtualHost *:80>
ServerName iot.mydomain.com
ServerAlias iot
WSGIDaemonProcess iot.local python-path=/home/name/PycharmProjects/iotdata
WSGIProcessGroup iot.local
WSGIScriptAlias / /home/name/PycharmProjects/iotdata/iotdata/wsgi.py process-group=iot.local
#WSGIPythonPath /home/name/PycharmProjects/iotdata
Alias /static/ /home/name/PycharmProjects/iotdata/static/
<Directory /home/name/PycharmProjects/iotdata>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/name/PycharmProjects/iotdata/static>
Require all granted
</Directory>
</VirtualHost>
I am trying to follow the tutorial on Deploying static files on Apache using mod_wsgi from the 1.6 Documentation. I already have a work in progress site deployed on Apache using mod_wsgi but I need to learn how to correctly deploy static files instead of linking to external Bootstrap CSS as I have been doing.
My issue is I have no idea where the below sample settings from the documentation is or where it should go.
Below is the relevant DjangoProject text
If, however, you have no option but to serve media files on the same
Apache VirtualHost as Django, you can set up Apache to serve some URLs
as static media, and others using the mod_wsgi interface to Django.
This example sets up Django at the site root, but explicitly serves
robots.txt, favicon.ico, any CSS file, and anything in the /static/
and /media/ URL space as a static file. All other URLs will be served
using mod_wsgi:
It then gives the below sample code which I will need to modify
Alias /robots.txt /path/to/mysite.com/static/robots.txt
Alias /favicon.ico /path/to/mysite.com/static/favicon.ico
AliasMatch ^/([^/]*\.css) /path/to/mysite.com/static/styles/$1
Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/
<Directory /path/to/mysite.com/static>
Require all granted
</Directory>
<Directory /path/to/mysite.com/media>
Require all granted
</Directory>
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Followed by some clarification instruction
If you are using a version of Apache older than 2.4, replace Require
all granted with Allow from all and also add the line Order deny,allow
above it.
There are some similarities to my below <VirtualHost> file. Should I just add it to this? Or should it be stored in another location?
<VirtualHost *:80>
ServerName phaedrus.scss.tcd.ie/bias_experiment
ServerAlias phaedrus.scss.tcd.ie
WSGIScriptAlias /bias_experiment/ /var/www/bias_experiment/src/bias_experiment/index.wsgi
Alias /static/ /var/www/bias_experiment/src/bias_experiment/static/
<Location "/static/">
Options -Indexes
</Location>
</VirtualHost>
Any help would be great.
Yes, this is supposed to go in the same place as your virtualhost configuration.