404 not found, nginx looking for the default path 'etc/nginx/html/index.html' on NextJS application

Viewed 340

I'm currently in need of some help with this 404 issue I've been stuck on for days now. My system is running CentOS7 (CPanel, VPS) and it uses engintron for the nginx reverse proxy and pm2 to keep my next.js application running.

default.conf

server {
    #listen 80 default_server;
    listen 80;
    server_name my.domain.name domain.name;

    location / {
        # reverse proxy for next server
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
    
    location /_next/static/ {
        alias path/to/nextjs/static/folder;
        expires 365d;
        access_log off;
    }

    # deny all; # DO NOT REMOVE OR CHANGE THIS LINE - Used when Engintron is disabled to block Nginx from becoming an open proxy

    # Set the port for HTTP proxying
    set $PROXY_TO_PORT 8080;

    include common_http.conf;

}

All the other files I haven't touched, so it's safe to rule them out as they're the default ones that come with engintron.

Connecting to my.domain.name, gives me this error in the console.

"/etc/nginx/html/index.html" is not found (2: No such file or directory), client: ::ffff:my.ip.address, server: my.domain.name, request: "GET / HTTP/2.0", host: "my.domain.name"

My best guess on why this problem occurs is because my domain/server can't receive the files or doesn't have permission through the proxy at all as getting the data at 127.0.0.1:3000 via curl http://127.0.0.1/3000 returns my site's code in full.

Any ideas on what could be causing this? Have an amazing rest of your day :)

1 Answers

Engintron can make proxying to Node apps easy. Have a look at the docs (engintron.com/docs) as well as the "custom rules" files in WHM > Plugins > Engintron.

As long as you load your Node site in your public_html folder for the given account (Apache cannot render it either way, so it's not an issue) and _next/static/ is inside that public_html folder (for symmetrical proxying), then the Node.js proxy rule you set in Engintron's custom rules (again see the docs) will be sufficient for your needs.

I would also recommend you revert any changes you did in Engintron's Nginx config files.

Related