Webserver using nginx

February 7, 2024, 11:46

cylorun

I am trying to host a webserver/apion domain i bought through name.com, i honestly don't know much about this and nether did i find much about it online. The website/api im trying to host is just a simple python Flask api. What i have done so far is setup nginx to make a proxy (?) that takes traffic from port 25565 -> 88 (not using port 80 since that did not work). I have not really done much more, i can now open up the site on my PC but only 404 errors show up. OS: Linux raspberrypi 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64 GNU/Linux nginx config:
server {
        listen 88 default_server;
        listen [::]:88 default_server;

        root /var/www/html;

        server_name my ip;

        location / {
                proxy_pass http://localhost:25565;
                proxy_set_header Host $host;
                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;

                try_files $uri $uri/ =404;
        }

oops.se

You need to add more details, OS version, and please spell out Raspberry Pi. And read https://discord.com/channels/818384379197784084/1189386838788542464 before posting

oops.se

First : Internet (your domain) - Home router - Raspberry Pi (with NGinx) 1. Your home router needs to be reachable from internet. 1.1 Static IP, some ISPs offers static IP for an extra fee. 1.2 Use a free DynamicDNS service 2. Configure your domain to point www or @ to use either your static IP provided by your ISP or the hostname you choose from your Dynamic DNS provider.

oops.se

3. You need to do port forward of port 80 in your Home router so it points to your Raspberry Pi IP address

oops.se

4. It is a good idea to configure a static IP on your Raspberry Pi

oops.se

Regarding 404, is a page can't be found, so if you post the NGinx config....

cylorun

server {
        listen 88 default_server;
        listen [::]:88 default_server;

        root /var/www/html;

        server_name my ip;

        location / {
                proxy_pass http://localhost:25565;
                proxy_set_header Host $host;
                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;

                try_files $uri $uri/ =404;
        }

cylorun

using 88 since 80 is taken by something else i think, also sorry i have no experience with this and im trying to learn so i might be quite clueless

oops.se

And how do you surf to the NGinx web, URL ?

oops.se

And how do the content of /var/www/html look like

cylorun

there is nothing there, i just forgot to remove it

cylorun

raspberrypi ip on port 88, when testing it on my pc

oops.se

and URL look like this http://<hostname>:88/index.htlm

cylorun

yeah, pretty much

cylorun


oops.se

I can't see a default doc in the NGinx config, so your URL cant work

oops.se

In my example URL I have an filename in the last part

cylorun

what im trying to do is host an API on this domain, for now thats all i need it to do, so i shouldnt need any pages, right?

cylorun

not sure if i confused you with saying website earlier, sorry about that

oops.se

An API is just a dynamically generated "page"

oops.se

So I think you should learn to walk before you run a marathon

cylorun

that would be a good idea...

oops.se

So read a tutorial on how to get started with NGinx

cylorun

👍 alright thanks

cylorun

ok sorry about that i now realise how incredibly that was

cylorun

i now know the basics of nginx and set it up correctly

oops.se

Nice

oops.se

So now you have a webserver that you can access

cylorun

yeah

cylorun

im using ngrok to port it to a website, which means that whenever i try to restart the server it, the api will have a different url. couldnt really figure out how to connect it to the domain, ithink it has something to do with that i dont have HTTPS setup for nginx

oops.se

So you have dynamic DNS and domain pointing to dynamic DNS working.

oops.se

And as for HTTPS that is also achievable, but a bit harder

oops.se

You can use either selfsigned certificate or "letsencrypt"

cylorun

i managed to connect the ngrok server to the dns(just a temporary thing to see if i can get anything to work), but it wouldnt load and gave an error saying that it was self signed. ill send more info once im home

oops.se

That make sense, and thats why I suggested letsencrypt.

cylorun

alright thanks ill look into that