簡體   English   中英

Apache - 部署 Django 應用程序時出現錯誤 403 Forbidden

[英]Apache - Error 403 Forbidden when deploying Django app

我正在嘗試在 Apache 中部署我的 Django 應用程序,但這是不可能的。 當我輸入 url 時,它說 403 Forbidden 並且沒有任何反應。

我曾嘗試觀看許多教程,但無法修復我的錯誤。 我正在使用 CentOS 7。

這是我的 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>


這是我的 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>

在 /var/www/html 目錄中部署應用程序是不安全的,因為它是默認的 apache 文件夾。 檢查您的 apache 日志 (error.log) 和 django 文件夾權限。

關於此有 2 個常見錯誤,請檢查這些:

  • 文件或文件夾權限不正確
  • .htaccess 文件中的設置不正確

檢查您的網址路徑、權限和特權

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM