簡體   English   中英

Django 部署:錯誤 403 Forbidden 您無權訪問此服務器上的 /

[英]Django Deployment: Error 403 Forbidden You don't have permission to access / on this server

I'm currently deploying my Django app into a CentOS 7 Server (CentOS Linux release 7.8.2003) based on Django documentation here . 但是我遇到了下面錯誤日志中所述的這個問題(錯誤 403)。

注意事項:

  1. 是的,我能夠通過虛擬環境端口 8000 運行服務器。

  2. 我使用的數據庫是 mysql( 指南)。

  3. 這和apache設置的訪問權限有關系嗎? 目前,我已將 apache 的權限設置如下:

 sudo chown:apache colus_cafe/ sudo chown -R:apache colus_cafe/colus_cafe/media
  1. Python 版本 3.6.8 和 WSGI python36-mod_wsgi.x86_64(指南)。
  2. 我嘗試了什么:將根據給定的答案進行更新
    • 刪除並重新安裝虛擬環境。

/etc/httpd/conf.d/django.conf:

Alias /static /home/colus/colus_cafe/colus_cafe/static
<Directory /home/colus/colus_cafe/colus_cafe/static>
        Require all granted
</Directory>

Alias /media /home/colus/colus_cafe/colus_cafe/media
<Directory /home/colus/colus_cafe/colus_cafe/media>
        Require all granted
</Directory>

<Directory /home/colus/colus_cafe/colus_cafe>                                                                       
        <Files wsgi.py>
            Require all granted
    </Files>
</Directory>

WSGIScriptAlias / /home/colus/colus_cafe/colus_cafe/wsgi.py
WSGIDaemonProcess colus_cafe_app python-home=/home/colus/colus_cafe/env python-path=/home/colus/colus_cafe
WSGIProcessGroup colus_cafe_app

/etc/httpd/logs/error_log

Current thread 0x00007fee066d6880 (most recent call first):                                                          

[Wed Jul 08 07:11:09.691137 2020] [mpm_prefork:notice] [pid 10044] AH00170: caught SIGWINCH, shutting down gracefully
[Wed Jul 08 07:11:10.768060 2020] [core:notice] [pid 10231] SELinux policy enabled; httpd running as context system_$
[Wed Jul 08 07:11:10.769024 2020] [suexec:notice] [pid 10231] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/$[Wed Jul 08 07:11:10.789925 2020] [so:warn] [pid 10231] AH01574: module wsgi_module is already loaded, skipping      
[Wed Jul 08 07:11:10.793580 2020] [lbmethod_heartbeat:notice] [pid 10231] AH02282: No slotmem from mod_heartmonitor  
[Wed Jul 08 07:11:10.796988 2020] [mpm_prefork:notice] [pid 10231] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/4.6.2 Pyt$[Wed Jul 08 07:11:10.797021 2020] [core:notice] [pid 10231] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'   
[Wed Jul 08 07:11:10.798024 2020] [wsgi:warn] [pid 10232] (13)Permission denied: mod_wsgi (pid=10232): 
Unable to stat Python home /home/colus/colus_cafe/env. 
Python interpreter may not be able to be initialized correctly. 
Verify the supplied path and access permissions for whole of the path. 
Fatal Python error: Py_Initialize: Unable to get the locale encoding                                           
ModuleNotFoundError: No module named 'encodings'

根據 Maarten 的評論,我找到了這個問題的答案。

  1. 我需要更改 apache 的訪問權限,以使用chmod讀取和執行 django 項目文件夾。 但是,這稍后會在下面顯示另一個問題。 在此處輸入圖像描述

/etc/httpd/logs/error_log

 failed to map segment from shared object permission denied mysql.
  1. 然后我發現錯誤顯示Python(在虛擬環境中)無法執行包(mysqlclient)。 因此,可以在此處找到解決方案,更改“httpd_sys_script_exec_t”的安全上下文,允許 Apache 執行。

我希望這可以幫助任何遇到這個問題的人。 如果我犯了任何不良做法或錯誤,請發表評論。

謝謝你,祝你有美好的一天。

暫無
暫無

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

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