Passenger Apache - 禁止您無權存取此資源

Passenger Apache - 禁止您無權存取此資源

我被配置困住ApachePassenger。我花了幾天時間尋找解決方案。我按照這個說明操作。我在瀏覽器中收到此訊息:

Forbidden

You don't have permission to access this resource.

httpd.conf

# Use /usr/bin/node by default.
PassengerNodejs /usr/bin/node

<VirtualHost *:80>

    ServerName example.com

    RewriteEngine On 
    RewriteCond %{HTTPS} off
    RewriteCond %{SERVER_NAME} =example.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

<VirtualHost *:443>

    ServerName example.com

    # Tell Apache and Passenger where your app's code directory is
        DocumentRoot /var/www/example.com
        PassengerAppRoot /var/www/example.com/

    # Tell Passenger that your app is a Node.js app
        PassengerAppType node
        PassengerStartupFile app.js

    # Relax Apache security settings
    <Directory /var/www/example.com>
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
        Options -MultiViews
        # Uncomment this if you're on Apache >= 2.4:
        Require all granted
    </Directory>

    CustomLog /var/log/httpd/example.com_access.log combined
    ErrorLog /var/log/httpd/example.com_error.log

    SSLEngine on
    SSLCertificateFile    /etc/letsencrypt/live/example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com/fullchain.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

</VirtualHost>

在 /var/log/httpd/example.com_error.log 我得到:

[Sat Sep 04 07:24:00.473120 2021] [autoindex:error] [pid 907862:tid 139932467173120] [client 85.89.184.79:50337] AH01276: Cannot serve directory /var/www/example.com/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

文件權

drwxr-xr-x. 5 root   root  102 Sep  3 23:53 ..
drwxr-xr-x. 8 root   root  163 Sep  4 07:11 .git
-rw-r--r--. 1 root   root   35 Sep  4 07:11 .gitignore
-rw-r--r--. 1 root   root  215 Sep  4 07:11 README.md
-rw-r--r--. 1 root   root  390 Sep  4 07:11 app.js
drwxr-xr-x. 3 root   root   21 Sep  4 07:12 node_modules
-rw-r--r--. 1 root   root 2655 Sep  4 07:12 npm-shrinkwrap.json
-rw-r--r--. 1 root   root  318 Sep  4 07:11 package.json
drwxr-xr-x. 2 root   root   22 Sep  4 07:11 public

curl http://127.0.0.1:3000/從 Node.js/io.js + Connect.js 回傳 Hello!

有什麼我應該檢查的嗎?

答案1

此錯誤意味著目錄中沒有預設索引文件,考慮到您提到的文件列表,這顯然是您的情況。

解決方案:

  1. 在公共目錄中建立一個空白的 index.html 頁面。

    touch /var/www/example.com/index.html
    
  2. 修改httpd.conf中的選項指令並新增索引:

    Options -MultiViews -Indexes
    
  3. 重新啟動/重新載入 httpd

    service httpd reload
    

編輯

再次查看您的 httpd.conf,您似乎沒有將 DocumentRoot 指向您的公共目錄所在的位置。所以:

  1. 將目前的 DocumentRoot 替換為 /var/www/example.com/public:
DocumentRoot /var/www/example.com/public
  1. 將目錄路徑也更改為相同的路徑:
<Directory /var/www/example.com/public>

欲了解更多信息,請參閱客運網站

相關內容