简体   繁体   中英

Apache - Error 403 Forbidden when deploying Django app

I am trying to deploy my Django application in Apache but it is impossible. When I enter the url it says 403 Forbidden and nothing happens.

I have tried watching many tutorials but have not been able to fix my error. I'm using CentOS 7.

This is my site.com.conf => /usr/local/apache/conf.d/vhost/myproject.com.conf

<VirtualHost myprojectIP:8181>
    ServerName myproject.com
    ServerAlias www.myproject.com
    ServerAdmin myproject@myproject.com
    DocumentRoot /var/www/html/myproject
    UseCanonicalName Off
    ScriptAlias /cgi-bin/ /home/admin/public_html/cgi-bin/

    <IfModule mod_setenvif.c>
        SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on
    </IfModule>

    <IfModule mod_userdir.c>
        UserDir disabled
        UserDir enabled admin
    </IfModule>

    <IfModule mod_suexec.c>
        SuexecUserGroup admin admin
    </IfModule>

    <IfModule mod_suphp.c>
        suPHP_UserGroup admin admin
        suPHP_ConfigPath /home/admin
    </IfModule>

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid admin admin
    </IfModule>

    <IfModule itk.c>
        AssignUserID admin admin
    </IfModule>

  <Directory /var/www/html/myproject>    
        Options -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
        AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
        SSLRequireSSL
    </Directory> 

    <Directory /var/www/html/venv>
      Require all granted
    </Directory>

    Alias /static /var/www/html/myproject/templates/static   
    <Directory /home/admin/public_html/myproject/templates/static>  
        Require all granted 
    </Directory> 
  
    WSGIProcessGroup remesas 
    WSGIScriptAlias / /var/www/html/myproject/remesas/wsgi.py
  
</VirtualHost>


This is my site.com.ssl.conf => /usr/local/apache/conf.d/vhost/myproject.com.ssl.conf

<VirtualHost myprojectIP:8443>
    ServerName myproject.com
    ServerAlias www.myproject.com
    ServerAdmin myproject@myproject.com
    DocumentRoot /var/www/html/myproject
    UseCanonicalName Off
    ScriptAlias /cgi-bin/ /home/admin/public_html/cgi-bin/

   #SSL CONFIGURE HERE

   ####################

    <IfModule mod_userdir.c>
        UserDir disabled
        UserDir enabled admin
    </IfModule>

    <IfModule mod_suexec.c>
        SuexecUserGroup admin admin
    </IfModule>

    <IfModule mod_suphp.c>
        suPHP_UserGroup admin admin
        suPHP_ConfigPath /home/admin
    </IfModule>

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid admin admin
    </IfModule>

    <IfModule itk.c>
        AssignUserID admin admin
    </IfModule>

  <Directory /var/www/html/myproject>    
        Options -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
        AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
        SSLRequireSSL
    </Directory> 

    <Directory /var/www/html/venv>
      Require all granted
    </Directory>

    Alias /static /var/www/html/myproject/templates/static   
    <Directory /home/admin/public_html/myproject/templates/static>  
        Require all granted 
    </Directory> 
  
    WSGIDaemonProcess remesas python-path=/var/www/html/myproject:/var/www/html/venv/lib/python3.6/site-packages 
    WSGIProcessGroup remesas 
    WSGIScriptAlias / /var/www/html/myproject/remesas/wsgi.py
  

</VirtualHost>

This is insecure to deploy app at /var/www/html directory, 'cause it is a default apache folder. Check your apache logs (error.log) and django folder permissions.

there are 2 common error about this, check these:

  • Incorrect file or folder permissions
  • Incorrect settings in the .htaccess file

check your url path, Permission and privileges

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM