skip to Main Content

I am working on deploying a Django project with apache2 and MOD_WSGI. When I run the server, I am unable to access the website and I get the error on the site,

Forbidden
You don't have permission to access this resource.
Apache/2.4.29 (Ubuntu) Server at testnexusstudy.com Port 8081

enter image description here
I have set up everything I think I need like the conf file,

<VirtualHost *:8081>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html


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

#Include conf-available/serve-cgi-bin.conf

Alias /static /root/StudBud1/static
<Directory /root/StudBud1/static>
    Require all granted
</Directory>

Alias /media /root/StudBud1/media
<Directory /root/StudBud1/media>
    Require all granted
</Directory>


<Directory /root/StudBud1/StudBud1>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIScriptAlias / /root/StudBud1/StudBud1/wsgi.py
WSGIDaemonProcess StudBud1 python-path=/root/StudBud1
WSGIProcessGroup StudBud1


</VirtualHost>

I have given all the permissions I thought were required for apache and here is my ls -la

drwxrwxr-x 12 root www-data  4096 Apr  5 19:36 StudBud1
-rw-rw-r--  1 root www-data 204800 Apr  5 19:36 db.sqlite3

Hopefully, some of you have experience with this type of error.

2

Answers


  1. I wouldn’t use or give root access to your web server for security reasons.

    I would create a user that only has access to the www-data group, make sure apache is also in that group.

    Some of these commands come from the Fedora distro, so they may be a little different from Debian.

    $ adduser deploy
    $ vim /etc/group
    

    In /etc/group:

    www-data:x:1003:apache,deploy
    

    /location/to/vhosts/website.conf (extraneous settings removed for clarity)

    <VirtualHost *:80>
    
        Alias /static/ /srv/vhosts/mywebsite/static/
        Alias /media/ /srv/vhosts/mywebsite/media/
        Alias /robots.txt /srv/vhosts/robots.txt
    
        <Directory /srv/vhosts/mywebsite/path/to/django/configs>
            Require all granted
        </Directory>
    
        <Directory /srv/vhosts/mywebsite/static>
          Require all granted
        </Directory>
    
        <Directory /srv/vhosts/mywebsite/media>
          Require all granted
        </Directory>
    
        <Location "/robots.txt">
          SetHandler None
          Require all granted
        </Location>
    
        WSGIDaemonProcess mywebsite python-home=/srv/vhosts/mywebsite/.venv python-path=/srv/vhosts/mywebsite/
        WSGIProcessGroup mywebsite
        WSGIScriptAlias / /srv/vhosts/mywebsite/path/to/django/configs/wsgi.py
    
    </VirtualHost>
    

    Then restart apache

    Once that is done, make sure to give your directories to the user and group www-data
    as sudo (-R for recursive)

    $ sudo chown -R deploy:www-data /path/to/webroot
    
    Login or Signup to reply.
  2. I’m a total beginner.
    On a fresh install I had to set the permissions for the /var/www/html directory.
    By default they were -rw——-
    I typed sudo chmod 775 * and it fuctionned.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search