Django部署:禁止错误403您无权访问此服务器上的/

时间:2020-07-08 11:42:18

标签: django apache centos7 wsgi

我目前正在根据Django文档here将Django应用程序部署到CentOS 7服务器(CentOS Linux版本7.8.2003)中。但是我在下面的错误日志中遇到了这个问题(错误403)。

注意事项:

  1. 是的,我能够通过虚拟环境端口8000运行服务器。

  2. 我正在使用的数据库是mysql(guide)。

  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(guide)。
  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'

1 个答案:

答案 0 :(得分:0)

基于Maarten的评论,我找到了解决此问题的答案。

  1. 我需要使用chmod来更改apache的访问权限,以读取并执行django项目文件夹。但是,这稍后在下面显示了另一个问题。 enter image description here

/ etc / httpd / logs / error_log

failed to map segment from shared object permission denied mysql.
  1. 然后我发现错误表明Python(在虚拟环境中)无法执行软件包(mysqlclient)。因此,可以找到here的解决方案,该解决方案更改了允许Apache执行的“ httpd_sys_script_exec_t”安全上下文。

我希望这会对遇到此问题的任何人有所帮助。并且,如果我有任何不良做法或错误,请发表评论。

谢谢您,祝您愉快。

相关问题