![乘客阿帕奇 - 禁止您无权访问此资源](https://linux22.com/image/770198/%E4%B9%98%E5%AE%A2%E9%98%BF%E5%B8%95%E5%A5%87%20-%20%E7%A6%81%E6%AD%A2%E6%82%A8%E6%97%A0%E6%9D%83%E8%AE%BF%E9%97%AE%E6%AD%A4%E8%B5%84%E6%BA%90.png)
我被配置问题难住了Apache
。Passenger
我花了几天时间寻找解决方案。我遵循这个说明。我在浏览器中收到此消息:
Forbidden
You don't have permission to access this resource.
httpd配置文件
# 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
这个错误意味着目录中没有默认索引文件,考虑到您提到的文件列表,这显然是您的情况。
解决方案:
在公共目录中创建一个空白的 index.html 页面。
touch /var/www/example.com/index.html
修改httpd.conf里面的Options指令,添加Indexes:
Options -MultiViews -Indexes
重新启动/重新加载 httpd
service httpd reload
编辑:
再次查看您的 httpd.conf,似乎您没有将 DocumentRoot 指向您的公共目录。因此:
- 将当前的 DocumentRoot 替换为 /var/www/example.com/public:
DocumentRoot /var/www/example.com/public
- 将目录路径也更改为相同路径:
<Directory /var/www/example.com/public>
有关详细信息,请参阅乘客网站