Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 Error on GET /api/config #124

Open
madushanTHAMB opened this issue Jan 15, 2025 · 17 comments
Open

404 Error on GET /api/config #124

madushanTHAMB opened this issue Jan 15, 2025 · 17 comments

Comments

@madushanTHAMB
Copy link

madushanTHAMB commented Jan 15, 2025

Issue: 404 Error on GET /api/config

Hello guys !

Description

I am encountering a 404 Not Found error when attempting to access /api/config on the frontend of the nfsen-ng web interface. The backend is functioning correctly, and I can successfully parse files, generate nfcapd files daily, and create RRD files without any issues. However, the frontend fails to retrieve the configuration from the /api/config endpoint.


Environment and Setup

OS and Web Server

  • OS: Arch Linux
  • Web Server: Apache (httpd)
  • PHP Version: 8.3

nfsen-ng Setup

  • Repository: Cloned into /data/nfsen-ng/
  • Frontend: Located in /data/nfsen-ng/frontend/
  • Backend: Located in /data/nfsen-ng/backend/
  • RRD Files: Located in /data/nfsen-ng/backend/datasources/data
  • NFCAPD Files: Generated in /data/nfsen-ng/profiles-data/

Current Configuration

Apache Configuration (httpd.conf)

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /data/nfsen-ng/frontend

    # Alias pour le frontend
    Alias /nfsen-ng/ /data/nfsen-ng/frontend/

    <Directory /data/nfsen-ng/frontend/>
        AllowOverride All
        Require all granted
    </Directory>

    # Configuration pour le backend (nécessaire pour les réécritures définies dans .htaccess)
    <Directory /data/nfsen-ng/backend/>
        AllowOverride All
        Require all granted
    </Directory>

    # Journaux personnalisés pour déboguer
    ErrorLog /var/log/httpd/nfsen-ng-error.log
    CustomLog /var/log/httpd/nfsen-ng-access.log combined

    # Définir le niveau des logs pour le débogage des réécritures
    LogLevel alert rewrite:trace3
</VirtualHost>

nfsen-ng Settings (settings.php):

<?php

$nfsen_config = [
    'general' => [
        'filters' => [
            'proto udp',
            'proto tcp',
        ],
        'formats' => [
            'external_interfaces' => '%ts %td %pr %in %out %sa %sp %da %dp %ipkt %ibyt %opkt %obyt %flg',
        ],
        'db' => 'RRD',
        'processor' => 'NfDump',
        'ports' => [],
        'stored_output_formats' => [],
        'stored_filters' => [],
        'sources' => [
            'PFC_CHA',
        ],        
    ],
    'frontend' => [
        'reload_interval' => 60,
        'defaults' => [
            'view' => 'graphs',
            'graphs' => [
                'display' => 'sources',
                'datatype' => 'flows',
                'protocols' => ['any'],
            ],
            'flows' => [
                'limit' => 50,
            ],
            'statistics' => [
                'order_by' => 'bytes',
            ],
            'table' => [
                'hidden_fields' => [
                    'flg', 'fwd', 'in', 'out', 'sas', 'das'
                ],
            ],
        ],
    ],
    'nfdump' => [
        'binary' => '/usr/local/bin/nfdump',
        'profiles-data' => '/data/nfsen-ng/profiles-data/',
        'profile' => 'live',
        'max-processes' => 10,
    ],
    'log' => [
        'priority' => \LOG_INFO,
    ],
];

Apache Modules - The following modules are enabled:

rewrite_module (shared)
deflate_module (shared)
expires_module (shared)
php_module (shared)

My nfcapd command:

/usr/local/bin/nfcapd -vv -D -p 9995 -B 20971520 -S 1 -P /data/nfsen-ng/var/run/p9995.pid -z=lz4 -t 300 -I PFC_CHA -w /data/nfsen-ng/profiles-data/live/PFC_CHA -T all

Frontend Error:

On the web interface, the /api/config endpoint returns a 404 Not Found.
The following error is observed in the browser console:
GET http://X.X.X.X/api/config 404 (Not Found)

It's been 2 days i'm on it and i can't find any solution in the issues, is it maybe because i'm not putting the files in /var/www/html ? I don't really know, so if you could help me i'll be great :)
Thanks !

@mbolli
Copy link
Owner

mbolli commented Jan 15, 2025

Try with

<Directory /data/nfsen-ng/>
    AllowOverride All
    Require all granted
</Directory>

instead of

    <Directory /data/nfsen-ng/frontend/>
        AllowOverride All
        Require all granted
    </Directory>

    # Configuration pour le backend (nécessaire pour les réécritures définies dans .htaccess)
    <Directory /data/nfsen-ng/backend/>
        AllowOverride All
        Require all granted
    </Directory>

@madushanTHAMB
Copy link
Author

Hello sir !

I tried it but always the same, i restart httpd and nfsen-ng to make sure but same.

image

with your change my httpd_conf was this :

<VirtualHost *:80>
ServerName localhost
DocumentRoot /data/nfsen-ng/frontend

# Alias pour le frontend
Alias /nfsen-ng/ /data/nfsen-ng/frontend/

<Directory /data/nfsen-ng/>
    AllowOverride All
    Require all granted
</Directory>
# Journaux personnalisés pour déboguer
ErrorLog /var/log/httpd/nfsen-ng-error.log
CustomLog /var/log/httpd/nfsen-ng-access.log combined

# Définir le niveau des logs pour le débogage des réécritures
LogLevel alert rewrite:trace3

I tried a lot of things but i don't know why it is so complicated, people had no a lot of problem

Thank you for your help

@mbolli
Copy link
Owner

mbolli commented Jan 15, 2025

what does it say if you create a file phpinfo.php with content <?php phpinfo();?> and open it in the browser?

@madushanTHAMB
Copy link
Author

I already did this to see if it's taking my php:

image

Do i need to give you more informations about this page ?

I can give you informations about what it's scanning or done as data:

image

image

@mbolli
Copy link
Owner

mbolli commented Jan 16, 2025

Well this is weird. The api/config endpoint should be rewritten using mod rewrite. This is probably not happening, and that's why it results in a 404. Are you 100% sure the module is enabled? Do you have anything else in the logs which could explain this behavior? Can you test mod_rewrite with another RedirectRule, e.g. to redirect everything to google.com?

@madushanTHAMB
Copy link
Author

Hello !
I have nothing in the logs, no error log.

For the backend i have create a service(i always restart everything to run) :

cat /etc/systemd/system/nfsen-ng.service

[Unit]
Description=nfsen-ng
After=network-online.target

[Service]
Type=simple
RemainAfterExit=yes
Restart=always
StartLimitIntervalSec=0
RestartSec=2
ExecStart=su - http --shell=/bin/bash -c '/data/nfsen-ng/backend/cli.php start'
ExecStop=su - http --shell=/bin/bash -c '/data/nfsen-ng/backend/cli.php stop'

[Install]
WantedBy=multi-user.target


Here is my module rewrite :

Image

So i test for the rewrite, it works with that configuration it redirect me to google:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /data/nfsen-ng/frontend

    # Alias pour le frontend
    Alias /nfsen-ng/ /data/nfsen-ng/frontend/

    <Directory /data/nfsen-ng/frontend/>
        AllowOverride All
        Require all granted
    </Directory>

    # Test de réécriture
    RewriteEngine On
    RewriteRule ^.*$ https://www.google.com [R=301,L]

    ErrorLog /var/log/httpd/nfsen-ng-error.log
    CustomLog /var/log/httpd/nfsen-ng-access.log combined
</VirtualHost>

Image

@mbolli
Copy link
Owner

mbolli commented Jan 16, 2025

hmm does the test rewrite also work in the .htaccess in the nfsen-ng folder?

@madushanTHAMB
Copy link
Author

madushanTHAMB commented Jan 16, 2025

I tried this( i delete from the redirection from the httpd_conf):

Image

It's not redirecting to google !

Image

@mbolli
Copy link
Owner

mbolli commented Jan 16, 2025

can you remove <IfModule> around the rules?

@madushanTHAMB
Copy link
Author

I tried this :

Image

But same

@mbolli
Copy link
Owner

mbolli commented Jan 16, 2025

you still need to have <Directory /data/nfsen-ng/> in the virtual host.

@madushanTHAMB
Copy link
Author

madushanTHAMB commented Jan 16, 2025

I didn't touch this file :

Image

I don't really wanna bother you with that aha

@mbolli
Copy link
Owner

mbolli commented Jan 16, 2025

yes but it needs to AllowOverride the .htaccess which is in /data/nfsen-ng - not in /data/nfsen-ng/frontend.

@madushanTHAMB
Copy link
Author

madushanTHAMB commented Jan 16, 2025

Ok the error change :

Image

with that configuration as you said:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /data/nfsen-ng/frontend

    # Alias pour le frontend
    Alias /nfsen-ng/ /data/nfsen-ng/frontend/

    <Directory /data/nfsen-ng/>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/nfsen-ng-error.log
    CustomLog /var/log/httpd/nfsen-ng-access.log combined
</VirtualHost>

So the redirect to google "works" because he tries to expose /api/config to www.google.com

@mbolli
Copy link
Owner

mbolli commented Jan 16, 2025

yes, nice. what happens now if you remove the redirect to google?

@madushanTHAMB
Copy link
Author

madushanTHAMB commented Jan 16, 2025

Getting back to 404 :

Image

with that conf :

Image

@madushanTHAMB
Copy link
Author

Hello!
I pinging you back to see if you have anyone that have that kind of problem or it's only me ?
Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants