0

I'm stuck with Apache with Passenger configuration. I spent a few days looking for a solution. I follow this instructions. I'm getting this message in the browser:

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>

In /var/log/httpd/example.com_error.log I get:

[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

File rights

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/ returns Hello from Node.js/io.js + Connect.js!

Is there anything i should check?

neuroine
  • 1
  • 3

1 Answers1

0

This error means there is no default index file in the directory and that is clearly your case considering the files list you mentioned.

Solution:

  1. Create a blank index.html page inside your public directory.

    touch /var/www/example.com/index.html
    
  2. Modify Options Directive inside httpd.conf and add Indexes:

    Options -MultiViews -Indexes
    
  3. Restart/reload httpd

    service httpd reload
    

Edit:

Looking again at your httpd.conf, it seems you didn't point DocumentRoot to where your public directory is. Therefore:

  1. Replace the current DocumentRoot to /var/www/example.com/public:
DocumentRoot /var/www/example.com/public
  1. Change Directory path to the same path as well:
<Directory /var/www/example.com/public>

For more information, refer to Passenger website

  • Thank you for your answer. `index.html` files works fine, but Passenger runs the node app from `app.js` file. – neuroine Sep 04 '21 at 11:16
  • Thanks for next suggestions. Unfortunately that's not it. I think issue can by realated with user rights. When I `curl http://127.0.0.1:3000/` from server I get page content but when I curl using domain `http://example.com/` I get **403 Forbidden**. – neuroine Sep 04 '21 at 15:03
  • @neuroine well, you need a reverse proxy in that case not a root folder – djdomi Sep 06 '21 at 06:03