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.
Related
I am using Django with Multi Tenant Schemas. Everything is working well on production, but I am having an issue with image media Path.
My web server is an Apache2 installed on Ubuntu 18.04, in the site configuration file I have:
'''
ServerName qibot.com.br
ServerAlias tenant1.qibot.com.br tenant2.qibot.com.br tenant3.qibot.com.br
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /static /var/www/qibot_system/static
<Directory /var/www/qibot_system/static>
Require all granted
</Directory>
Alias /media /var/www/qibot_system/media/
<Directory /var/www/qibot_system/media/>
Require all granted
</Directory>
...
</VirtualHost>
'''
In this way, if the media (image or video) file is requested, django looks for
/var/www/qibot_system/media/ instead of
/var/www/qibot_system/media/tenant1 or
/var/www/qibot_system/media/tenant2 or
/var/www/qibot_system/media/tenant3
My question is, there is a way to set the variable on the end of /var/www/qibot_system/media/XXXXXXXXX to provide right path to django?
Best Regards
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 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.
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.
When I move /home/django/mysite to /var/www/html/mysite, and chown -R apache:apache, it works. But leaving in the home directory I get 403 forbidden.
I've literally spent a good 6 hours trying to get this to work. HUGE progress for me to see that it works in /var/www/html, as I know all my "config" settings are correct.
Here is my httpd.conf
(first setting had to add to stop 503 internal server error)
WSGISocketPrefix /var/run/wsgi
<VirtualHost 208.115.206.227:80>
WSGIDaemonProcess django user=django group=django python-path=/home/django/mysite
WSGIProcessGroup django
ServerAdmin webmaster#mktrn.net
ServerName endor.mktrn.net
WSGIScriptAlias / /home/django/mysite/mysite/wsgi.py
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory /home/django/mysite/mysite>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
</VirtualHost>
So again, the above works if I just replace /home/django/mysite, with /var/www/html.
I'm running mod_wsgi as daemon under the user django--so I don't think that is it. What am I doing wrong? I know it's not smart to put in /var/www/html, even if I have no document root, so really want to figure this out!
A home directory such as /home/django would normally not be readable to others and so the user that Apache runs as would not be able to see into that directory and so access would be forbidden. This is why it would work when you move it elsewhere.