Hi,
I have hosted my website according to your website guidance. And my website is working after hosting but when I try to access my media directory, I get this [Errno 13] Permission denied: /var/www/mysite2/media/
I have Built my website using Django framework python with apache server and mysql database. Actually I have hosted two websites on a single droplet. And my first website working properly, and this is my second website which causes this type of error.
So please help me.

This is my site.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
#DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

Alias /static /var/www/mysite/staticfiles
    <Directory /var/www/mysite/staticfiles>
            Require all granted
    </Directory>
    <Directory /var/www/mysite/mysite>  
            <Files wsgi.py>
                Require all granted
            </Files>
    </Directory>
WSGIDaemonProcess djangohost2 python-path=/var/www/mysite python-home=/var/www/mysite/djangohost2
WSGIProcessGroup djangohost2
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

And this permissions on /var/www/

drwxr-xr-x 13 root root 4096 Sep 19 13:05 mysite2
drwxr-xr-x 8 root root 4096 Sep 14 10:20 mysite1
drwxr-xr-x 2 root root 4096 Sep 14 08:58 html
edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there @akshaykoshti401,

I would recommend starting with checking your Nginx error log:

  • sudo tail -100 /var/log/nginx/error.log

It is possible that the Nginx user does not have read permissions for the /var/www/mysite/staticfiles folder and the files inside.

I could suggest changing the ownership of that folder and the files inside it to the Nginx user.

You can do that with the following command:

  • chown -R www-data: /var/www/mysite/staticfiles

Note that you might have to change the www-data with your actual Nginx user in case that you changed it.

Regards,
Bobby

Submit an Answer