【问题标题】:403 forbidden : You don't have permission to access this resource. Apache/2.4.29 (Ubuntu) Server Port 443403 禁止:您无权访问此资源。 Apache/2.4.29 (Ubuntu) 服务器端口 443
【发布时间】:2021-10-12 08:35:06
【问题描述】:

我正在尝试在 https 上运行我的实例,但它抛出了这个错误。

如果我删除 SSL,它在 http 上工作正常。

这是我在error.log 上收到的消息:

AH01630: client denied by server configuration: /home/ubuntu/readingroots/
 AH01630: client denied by server configuration: /home/ubuntu/readingroots/favicon.ico, referer: https://readingroots.in/

这是我的000-default.conf 文件配置文件:

<VirtualHost *:80>
        ServerAdmin admin@djangoproject.localhost
        ServerName readingroots.in
        ServerAlias www.readingroots.in
        DocumentRoot /home/ubuntu/readingroots
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        Alias /static /home/ubuntu/readingroots/static
<Directory /home/ubuntu/readingroots/static>
        Require all granted
</Directory>
<Directory /home/ubuntu/readingroots/readbus_project>
        <Files wsgi.py>
        Require all granted
        </Files>
</Directory>
        WSGIDaemonProcess readingroots python-path=/home/ubuntu/readingroots python-home=/home/ubuntu/readingroots/myprojectenv
        WSGIProcessGroup readingroots
        WSGIScriptAlias / /home/ubuntu/readingroots/readbus_project/wsgi.py

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.readingroots.in [OR]
RewriteCond %{SERVER_NAME} =readingroots.in
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

这是我的000-default-le-ssl.conf conf 文件:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin admin@djangoproject.localhost
        ServerName readingroots.in
        ServerAlias www.readingroots.in
        DocumentRoot /home/ubuntu/readingroots
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        Alias /static /home/ubuntu/readingroots/static
<Directory /home/ubuntu/readingroots/static>
        Require all granted
</Directory>
<Directory /home/ubuntu/readingroots/readbus_project>
        <Files wsgi.py>
        Require all granted
        </Files>
</Directory>


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/readingroots.in/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/readingroots.in/privkey.pem
</VirtualHost>
</IfModule>

我尝试了各种方法,但似乎没有任何效果。 请帮忙,如果我可以尝试任何方法,请告诉我。

编辑:

这是运行ls -l /home/ubuntu/readingroots 命令后的输出:

total 2164
drwxrwxr-x 5 ubuntu ubuntu      4096 Jul 26 18:23 actions
drwxrwxr-x 5 ubuntu ubuntu      4096 Jul 26 18:23 books
-rwxrwxr-x 1 ubuntu ubuntu     16384 Aug 14 05:32 celerybeat-schedule
drwxrwxr-x 5 ubuntu ubuntu      4096 Jul 26 18:23 chats
-rw-rw-r-- 1 ubuntu www-data 2120704 Aug 17 23:07 db.sqlite3
-rwxrwxr-x 1 ubuntu ubuntu     18446 Jul 15 19:21 edits.txt
-rwxrwxr-x 1 ubuntu ubuntu       656 Apr 26  2020 manage.py
drwxrwxr-x 3 ubuntu ubuntu      4096 Jul 24 03:20 media
drwxrwxr-x 5 ubuntu ubuntu      4096 Jul 24 06:05 myprojectenv
drwxrwxr-x 5 ubuntu ubuntu      4096 Jul 26 18:24 pages
drwxrwxr-x 4 ubuntu www-data    4096 Jul 26 05:22 readbus_project
drwxrwxr-x 8 ubuntu ubuntu      4096 Jul 26 18:40 static
drwxrwxr-x 7 ubuntu ubuntu      4096 Jul 26 18:38 static2
drwxrwxr-x 2 ubuntu ubuntu      4096 Jul 24 03:23 supervisor
drwxrwxr-x 4 ubuntu ubuntu      4096 Jul 24 03:23 templates
drwxrwxr-x 5 ubuntu ubuntu      4096 Jul 26 18:24 users
-rwxrwxr-x 1 root   root           0 Aug  5 05:43 vi

【问题讨论】:

  • apache 的用户 ID(通常为 www-data)是否具有对目录 /home/ubuntu/readingroots/ 及其所有子内容的读取权限?
  • @FedonKadifeli 是的,我相信。如何确认?
  • 运行ls -l /home/ubuntu/readingroots 获取文件权限,并将输出添加到您的问题中
  • @Jacob 运行命令,更新问题!

标签: apache ubuntu ssl


【解决方案1】:

您已在目录上设置了Require all granted 选项

/home/ubuntu/readingroots/readbus_project

/home/ubuntu/readingroots/静态

而您还需要 /home/ubuntu/readingroots 目录本身的指令。更多here

【讨论】:

    【解决方案2】:

    看来你使用的是python wsgi,你没有给它项目根节点的服务器权限

    来自 cmets 的错误

    [autoindex:error] [pid 27528:tid 140136830449408] [client 103.119.165.25:64522] AH01276: Cannot serve directory /home/ubuntu/readingroots/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive

    对于您的情况: cmets 中的此错误意味着您的服务器在端口 433 上看不到 wsgi

    在您的配置中,没有 WSGIScriptAliasWSGIDaemonProcess 或 433 conf 中的任何一个。

    它应该在433服务器配置以及80服务器配置中正确配置


    对于可能解决此问题的其他人也可能有所帮助:

    DocumentRoot /home/ubuntu/readingroots 本身没有 &lt;Directory&gt; 标记,因此您需要确保它存在

    类似这样的事情:

    <Directory /home/ubuntu/readingroots>
            Require all granted
    </Directory>
    

    如果 wsgi 服务器本身尝试获取属于其他用户而不是运行工作程序的用户的文件,则可能会出现此问题,因此您需要修复任何权限问题

    • 转到 ubuntu 上的 apache2 配置目录 /etc/apache2 - 你会找到一个名为 magicvars 的文件

    • apache-run-userapache-run-group 更改为您在 wsgi 服务中使用的内容

    • 在您的根目录上授予该用户和组所有权限

      chown -R user:group *
      
    • 如果您使用其他用户而不是编辑用户,则向组成员添加写入前提

      chmod g+x *
      // or
      chmod 774 *
      
    • 如果您不是,请将您的用户添加到该组

      sudo usermod -a -G group user
      

    我会推荐“NGNIX”作为 wsgi python 应用程序的代理,因为我两者都试过了,并且相信 apache2 不是 python 的好朋友

    【讨论】:

    • 嗨,我已经添加了“/home/ubuntu/readingroots”的权限。我仍然在 UI 上遇到同样的错误。当我在日志上收到此错误时:[autoindex:error] [pid 27528:tid 140136830449408] [client 103.119.165.25:64522] AH01276: Cannot serve directory /home/ubuntu/readingroots/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive 知道吗?
    • 这个错误意味着你的服务器在 433 端口上看不到 wsgi,我重新检查了配置,发现没有 WSGIScriptAliasWSGIDaemonProcess 或其中任何一个......你没有配置它
    • 嘿,非常感谢 Sharaf,它成功了!实际上,我在端口 443 的配置中也保留了 WSGIScriptAliasWSGIDaemonProcess,但出现重复名称错误。所以把它注释掉了,现在我试着把它改成另一个,它起作用了!!!!谢谢
    • 请将其添加到答案中,以便我接受。
    • 工作感谢...
    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 2020-12-26
    • 2018-07-12
    • 1970-01-01
    相关资源
    最近更新 更多