Getting 404 no matter what.. NGINX
Unanswered
Havana posted this in #help-forum
HavanaOP
Can't seem to get my project running...
132 Replies
HavanaOP
server {
listen 80;
server_name website.org www.website.org;
# Redirect all HTTP traffic to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name website.org www.website.org;
ssl_certificate [redacted];
ssl_certificate_key [PRIVATE_KEY_PATH]; # Managed by Certbot
# Proxy requests for Next.js generated content (_next/)
location /_next/ {
proxy_pass http://localhost: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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Proxy all other requests to Next.js app running on PM2
location / {
proxy_pass http://localhost: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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Redirect for Discord
location /discord {
return 301 https://discord.gg/link;
}
# Serve static files
location /help {
root [WEB_ROOT_PATH];
index help.html;
}
location /who {
root [WEB_ROOT_PATH];
index who.html;
}
# Serve JSON data directly
location /helplistThis is my config. I've tried many variations here to try to get it going, but always leads to error 404...
my /who and /help links work, those are static .html files, but the nextjs project is always 404....
my /who and /help links work, those are static .html files, but the nextjs project is always 404....
My nextjs app folder is inside my public_html folder on my vps
HavanaOP
curl -I http://localhost:3000
HTTP/1.1 200 OK
Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Accept-Encoding
x-nextjs-cache: HIT
X-Powered-By: Next.js
Cache-Control: s-maxage=31536000, stale-while-revalidate
Etag (idk if that's sensitive)
Content-Type: text/html; charset=utf-8
Content-Length: 15060
Date: Fri, 23 Aug 2024 10:00:46 GMT
Connection: keep-alive
Keep-Alive: timeout=5HavanaOP
😦
i get a 403 no matter what if i don't connect to the website via the port, i.e. mydomain.com:3000
HavanaOP
bump
pls dont set your nextjs folder insider your public html
have it in your home folder or anywhere else
u only use nginx as a reverse proxy so u dont need to use it as a webserver
next start is a webserver itself
also remove the /_next/
entry completely
HavanaOP
Hmmmm
My current setup works perfectly at port 3000 but not at the standard domain
@Havana My current setup works perfectly at port 3000 but not at the standard domain
send me your domain where your next server is hosted
i show u something
HavanaOP
is it dangerous to expose the nextjs folder in public_html?
the whole nextjs folder, including your src, logs and so on
will be available
unless u block it
so move it out
HavanaOP
hmm should i put it in private
@Havana hmm should i put it in private
put it in home
or just stop depending on the linux filesystem
and use docker
HavanaOP
thanks, im moving it now
HavanaOP
still doesnt work lol
everything is exactly the same
@gin also remove the /_next/
@Havana
HavanaOP
yeah ive done that
location / {
proxy_pass http://localhost: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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}ive just got this right now
location wise
and u get a forbidden?
send me your domain let me check
Original message was deleted
whats that?
HavanaOP
if i curl localhost:3000 from my vps i get back all of the html from my website
yeah nah something cursed going on
HavanaOP
indeed
HavanaOP
certbot
yeah
i read online that nextjs just doesnt like nginx, lol
u sure u have ur location / in your 443 block
sites available folder
HavanaOP
yes
ohooo
do you see a # managed by Certbot message anywhere
HavanaOP
there probably was and i removed it
i definitely upped the ssl cert
and
server {
if ($host = yourdomain {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name yourdomain
return 404; # managed by Certbot
}
if ($host = yourdomain {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name yourdomain
return 404; # managed by Certbot
}
HavanaOP
hmmm
do u have a entry like this
HavanaOP
i moved my shit out of my public_html and certbot will not find anything about my site now
it only shows my other domains heh
i dont have that currently , no
do u have much configuration on your vps
otherwise do a clean install and lmk
ill guide u trough the correct steps
reinstalling nginx can be tricky so its better to do a reinstall
HavanaOP
i just redeployed the cert
i have multiple domains and multiple objects running on my nginx
i cant uninstall it
ive got a live game that people play on there
heh
HavanaOP
nah
or prolly some gta rp server
HavanaOP
nah lol
a text based RPG (it's a mud)
idk what that is
lol
anyways yeah try reinstalling nginx
clean everything related to that
getting new certs for your domain is a matter of seconds
i did it like 100 times now
cause i messed some things up in the past aswell
ik how cursed it can become
HavanaOP
lol
damn
ok im at least getting here now
Success!
Your new web server is ready to use.xD
instead of the 404
@Havana ok im at least getting here now
Success!
Your new web server is ready to use.
did u reinstall something?
HavanaOP
nope
still didnt get this working
tried everything. epic stuff.
HavanaOP
I might have to decline on that one for now because somehow yesterday my VPS went to 100% and got fully cooked and it may be because I put my info on here.
it never goes above 5% normally.
I do appreciate that though.
HavanaOP
I checked with Btop.
My provider sent me an email though. Checked it and every single core was 100%, lol.
Something very messed up was going on.
your poor vps
lmao
@Havana I do appreciate that though.
alr ill hop out of the thread wish u good luck, but if u dont find a fix clear all your config files and reinstall nginx
that will fix it
HavanaOP
thanks bud
I think it's a bit complicated due to my control panel
HavanaOP
It does odd stuff with apache2 and nginx
using both
apache2 and nginx?
HavanaOP
yeah
why u using both
HavanaOP
I tried disabling apache2 and everything got wrecked
wait a sec
bruh
HavanaOP
I think nginx is being used as the reverse proxy
@Havana I think nginx is being used as the reverse proxy
yeah but nginx still runs on port 80
aswell as apache
lol
HavanaOP
yeah, but they're using some kind of magic to make it work because all of my other domains work