#Hosting starlight with NGINX (and Apache2 - httpd) only shows main page

313 messages ยท Page 1 of 1 (latest)

bleak panther
#

I set up a Seelf instance to host my docs on.
I have traefik proxying the actual domain to a docker container that runs NGINX with the config from the astro documentation (here) and of course has the dist folders content copied to /usr/share/nginx/html

The only accessible thing seems to be the index page and everything else is just 404 (also why javascript, css, images and whatever else don't appear)

https://staging-loot-table-modifier.docs.offsetmonkey538.top/

My exact nginx.conf file

worker_processes  1;

events {
  worker_connections  1024;
}

http {
  server {
    listen 80;
    server_name   _;

    root   /usr/share/nginx/html;
    index  index.html index.htm;
    include /etc/nginx/mime.types;

    gzip on;
    gzip_min_length 1000;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    error_page 404 /404.html;
    location = /404.html {
            root /usr/share/nginx/html;
            internal;
    }

    location / {
            try_files $uri $uri/index.html =404;
    }
  }
}
#

@pastel totem adammmmmm

#

Hosting starlight with NGINX only shows main page

pastel totem
# bleak panther <@732546370749071400> adammmmmm

you know you could have pinged me a link to this in your discord... without any context for the team, people are gonna think your doing something you shouldn't ๐Ÿคฃ

(full context i told him to make a support thread here in his discord because nginx configs are something i havent done for astro)

#

Felix you played with making nginx configs and astro yet?

quartz pine
#

I figured ๐Ÿ˜‚, but it was fun how much m is in there ๐Ÿ˜…

#

รคhhhhh, no, but if I see correctly, you only have location / and 404, so no other files will be servered

bleak panther
#

yeah

pastel totem
#

to be clear that is supposed to be a starlight site ๐Ÿ˜…

quartz pine
#

but unfortunately I don't know how to fix jt ๐Ÿค”

#

I myself have seen such pages on my self hosted Starlight pages often enough ๐Ÿ˜…

bleak panther
#

I can confirm that all the files exist in the docker container at /usr/share/nginx/html

quartz pine
#

but try this location instead:

location / {
      try_files $uri $uri/ /index.html;
    }
upper current
#

Have you tried to turn it off and back on again

quartz pine
#

OUT

pastel totem
upper current
#

Ive never setup nginx for Starlight but from what I can see. It should just work

quartz pine
upper current
pastel totem
quartz pine
#

what do you think I'm doing here?

pastel totem
#

i love his commit messages

quartz pine
#

guys, you should create threads in this threads for keeping the thread clean

upper current
#

Most of mine are like "why the f is not working"

bleak panther
#

seems to be the same still

quartz pine
#

me: "some changes"

upper current
#

Did you restart the server?

#

nginx -s reload

bleak panther
#

I'm pretty sure the container got restarted and the new config copied into it

#

ran cat /etc/nginx/nginx.conf in the container and it has the change, yeah

upper current
#

What does your traefik config look like?

upbeat goblet
#

I had to add this to my NGINX config when loading any assets:

 location ~ ^/(.+astro)(/|$) {
      proxy_pass              http://localhost:8885;
      proxy_pass_header Server;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
bleak panther
#

for the nginx container I have

labels:
  - "traefik.enable=true"

  - "traefik.http.routers.staging.rule=Host(`staging-loot-table-modifier.docs.offsetmonkey538.top`)"
  - "traefik.http.routers.staging.service=staging"
  - "traefik.http.services.staging.loadbalancer.server.port=80
pastel totem
upper current
#

You are missing a " on your last label

#
  • "traefik.http.services.staging.loadbalancer.server.port=80"
bleak panther
#

uhh no sorry that was just me being bad at copying

#

๐Ÿ˜…

upper current
#

Oh

upbeat goblet
bleak panther
upper current
#

Also try to just map your starlight site to a port outside of Traefik and then see if that loads it. If so, Traefik is the issue

bleak panther
#

ah yeah good call

pastel totem
upbeat goblet
#

Now that I look at the rest of my NGINX config, thay might not work for you as that only applied (I think) when we redirected all requests to a landing page while developing the site

bleak panther
#

not traefik related it seems

upper current
#

I also see this in the console..

quartz pine
#

me here still wondering why y'all write traffic wrong ๐Ÿ˜‚ jk

pastel totem
#

Everything is just redirecting to the index... instead of routing to each file

bleak panther
#

or well index it seems

bleak panther
quartz pine
#

yeah possibly

upper current
#

location / {
try_files $uri $uri/ /index.html;
}

Try just this then

bleak panther
#

"just this" as in....?

quartz pine
#

isn't this the same?

bleak panther
#

yeah

upper current
#

Oh yeah lol

#

Does your docker container have everything in it?

upper current
#

Yes.

#

Like does it have the css and js files?

bleak panther
#

those would be in _astro I'm guessing?

upper current
#

Yeah. Okay those are there. Uhh have you tried to clear your browser cache

pastel totem
upper current
#

Ahh okay

pastel totem
#

and was getting rewritten by nginx

bleak panther
#

plus when exposing the port I sent a different domain

pastel totem
#

currently there is something doing rewrite for every non-index entry

bleak panther
#

what would be the most simple nginx config I could try to use? this seems to have some fancy stuff and I'm wondering what would be the bare minimum that could be used here

upbeat goblet
#

Here's my location / { } code in our working site:

  location / {
      include cleavr-conf/example.com/*.conf.pre;
      proxy_pass              http://localhost:8885;
      proxy_pass_header Server;
      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_pass_header Server;
      include cleavr-conf/example.com/*.conf.post;
  }

I haven't worked with try_files before, so I'm unsure how that works. Obviously it's tailored to a Cleavr install so you'll need to modify it

upper current
#
worker_processes  1;

events {
  worker_connections 1024;
}

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  server {
    listen 80;
    server_name _;

    root /usr/share/nginx/html;
    index index.html;

    location / {
      try_files $uri $uri/ /index.html;
    }
  }
}
pastel totem
#

just trying to host a static starlight site through nginx

upbeat goblet
pastel totem
upper current
#

Are you sure the nginx container restarted and that the new config took place?

pastel totem
#

thats how i used to do all my web proxies before i switched to tunnels

upbeat goblet
bleak panther
upper current
#

Run nginx -s reload inside the container just to be sure

bleak panther
#

seems to be the same still

#

oh but I seem to have the favicon though? not sure when that changed but I don't believe that was showing at the start

upbeat goblet
#

Is the favicon in the public directory?

bleak panther
#

yep

upper current
#

Maybe try this in your config?

    location / {
      try_files $uri $uri/ =404;
    }

So remove the index.html fallback

bleak panther
#

and in the built version it's also at the root, net to 404 and index

#

uhh that's way worse

#

ah no I wasn't at the main page (but yeah initially it showed the starlight 404 for other pages)

quartz pine
#

why do you need the mime types in your nginx config?

bleak panther
#

that's what the astro docs say

quartz pine
#

could you just try something like:

events {}

http {
    server {
        listen 80;
        server_name _;

        location / {
            root /usr/share/nginx/html;
            try_files $uri $uri/ /index.html;
        }
    }
}
upper current
#

Okay. So its not finding any assets now. So can you check the container and make sure they are there?

#

What does your dockerfile look like?

quartz pine
#

good point ๐Ÿค”

#

should probably look something like

FROM nginx:latest AS runtime
COPY /starlight/nginx.conf /etc/nginx/nginx.conf
COPY /starlight/dist /usr/share/nginx/html
EXPOSE 80
EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]
bleak panther
#

right now I have

FROM nginx:alpine AS runtime
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./dist /usr/share/nginx/html

and then in my compose file

# Hosts a static page
services:
  web:
    build: .
    restart: unless-stopped
    ports:
      - "8081:80"
    networks:
      - traefik-proxy
    labels:
      - "traefik.enable=true"

      - "traefik.http.routers.staging.rule=Host(`staging-loot-table-modifier.docs.offsetmonkey538.top`)"
      - "traefik.http.routers.staging.service=staging"
      - "traefik.http.services.staging.loadbalancer.server.port=80"

networks:
  traefik-proxy:
    external: true
#

so dockerfile is wrong?

quartz pine
#

try appending the command at the end

bleak panther
#

alright

quartz pine
#

the last line from mine

#

not sure, but i think it meeds it to start the nginx?๐Ÿค”

bleak panther
#

but how would it be doing what it has been doing then?

upper current
#

Wait. Are you building the actual site before you copy it?

bleak panther
#

yes. I have a fun setup where github actions is actually what builds it

quartz pine
#

nice, me too works great ๐Ÿ™Œ

#

fun

    steps:
      - name: Check out the repo
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup PNPM
        uses: pnpm/action-setup@v3
        with:
          package_json_file: ./starlight/package.json

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: pnpm
          cache-dependency-path: ./pnpm-lock.yaml

      - name: Install dependencies
        run: pnpm install
        shell: bash
        working-directory: ./starlight

      - name: Build Website
        run: pnpm run build
        shell: bash
        working-directory: ./starlight
bleak panther
#

(please send your workflow, I'm guessing mine is very overcomplicated)

#

oh you already did

#

:D

quartz pine
#

faster than light

#

but you need to adopt some things

bleak panther
#

yep yep

quartz pine
#

eg working dir is not necessary for you

bleak panther
#

ehh it is actually but sure

#

docs is in docs subfolder

quartz pine
#

enc node version will also not work

quartz pine
#

but do you use npm? or pnpm?

bleak panther
#

pnpm

bleak panther
#

well now everything goes to the index again

#

is there anything else I could use instead of nginx? the docs mentioned some apache thing. I tried to use that initially, it didn't work at all, I switched to nginx, it didn't work at all, I fixed what was wrong (seelf didn't like bind mounts), it worked to the point it has now. Maybe I should try using that?

quartz pine
#

do you have the repo somewhere public?

pastel totem
bleak panther
#

well you can clearly see the GitHubGithub button

bleak panther
#

(haven't merged it yet)

quartz pine
#

apacha and nginx are just different providers, it should work with both but both require some exact setup, so will figure it out

quartz pine
bleak panther
#

maybe I should try what the docs had for apache and see if that works

#

now that the bind mount problem is fixed

upper current
#

Okay im back at my PC let me check the rpeo

#

repo

bleak panther
#

rpeo

quartz pine
#

rpeo

quartz pine
#

First thing I would do is rename default branch to "main"

#

xD

pastel totem
bleak panther
pastel totem
bleak panther
#

hmmm.... I wonder if anyone can notice what's wrong with this ๐Ÿ˜‚

pastel totem
#

apache, nginx?

#

and httpd.....

bleak panther
#

master.

#

welp seems like it still does the same thing with apache as well

#

and the other pages say Forbidden?

upper current
#

I cloned it locally and im checking it out now to see

bleak panther
#

not 404

upper current
#

Okay So locally im able to hit the .css files at least

bleak panther
#

what are you expecting to happen locally? It worked fine on cloudflare pages and works fine locally

quartz pine
#

wait, locally you can build the docker image and it works?

bleak panther
#

oh nvm as a docker image. Right makes sense

#

haven't tried that

quartz pine
#

yes, that's how Im currently testing it, no problem

#

hm, works

#

try with this dockerfile:

FROM node:lts AS build
WORKDIR /docs
COPY . .
RUN npm i
RUN npm run build

FROM httpd:2.4 AS runtime
COPY --from=build /docs/dist /usr/local/apache2/htdocs/
EXPOSE 80
bleak panther
#

sure, in a second

#

gotta change the github workflow to upload the whole repo i guessss

upper current
#

Interesting.

bleak panther
#

interesting?

quartz pine
#

makes it more consistent if you wanna try locally

bleak panther
#

yep yep

upper current
#

What difference does the build step in the docker file vs just building and then copying do?

quartz pine
#

thats not the only diff

quartz pine
#

you basically would need that if you wanna build in github action I guess:

FROM httpd:2.4 AS runtime
COPY --from=build /docs/dist /usr/local/apache2/htdocs/
EXPOSE 80
bleak panther
#

yep yep

#

that didn't work

bleak panther
#

but yeah wait a moment

quartz pine
#

but could be a traefik problem, idk

#

cant test this easily locally

upper current
#

I see
FROM nginx:alpine AS runtime
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
in the config

bleak panther
#

already directly exposed the port

bleak panther
quartz pine
upper current
#

Ohh

bleak panther
#

which removes the wrong cmd

quartz pine
#

nice

#

there is still a 95% change it doesnt work btw

bleak panther
#

yeah the one with apache didn't work

quartz pine
#

do you still use the github action?

bleak panther
#

I am. Rewriting the workflow to send the full repo to seelf as we speak

#

or well I guess I should only include the docs folder

quartz pine
#

dont forget the build script, there is still nginx in there

bleak panther
#

ehh don't think that config will do anything if nginx isn't there to use it, but yeah

quartz pine
#

thats right yeah, but its confusing...

bleak panther
#

i'm going to just ingore the build.sh file for now anyway and have everything in the workflow

quartz pine
#

thats genious

#

tbh I quite dislike this scrpt

bleak panther
#

yeah! I know, right!?

quartz pine
#

yes

#

do you have the zip step anywhere else, because I have no xp if this could cause troubles

bleak panther
#

I had to use it because iirc it didn't want to find the archive.tar.gz file when I ran the commands separatwely there

quartz pine
#

maybe I dont get it, but do you have to compress somewhere? or is this just because you can? I personally think it could be an additional step where we mess up, but as I said, no idea

bleak panther
#

I need to compress it to a tar file to then send it to seelf because tar.gz is all it'll accept

#

contributor??

quartz pine
#

ah

bleak panther
#

why did I just become blu

quartz pine
#

oh you

#

nice

pastel totem
bleak panther
#

what did I contribute to? your pain and suffering?

quartz pine
#

oh coool, welcome to the club ๐Ÿ™Œ

upper current
#

Oh wait its working locally for me just fine

quartz pine
bleak panther
#

that isn't behind traefik

upper current
#

But im getting 403 here

bleak panther
upper current
#

Check the console

quartz pine
#

cause thre we have insecure activated:

bleak panther
#

that just makes traefik expose its dashboard over http

upper current
#

Yeah

quartz pine
#

ah

bleak panther
#

alright I think I got it to send the full docs folder to seelf and it is building the site on there now

upper current
#

Woooo

quartz pine
#

btw whats seelf?

bleak panther
#

it's like a self hosted uhh idk something

quartz pine
#

kk

bleak panther
#

Painless self-hosted deployment platform it calls itself

upper current
#

Yeah thats a joke lol

bleak panther
#

"painless"

pastel totem
bleak panther
#

yeah

quartz pine
pastel totem
#

interesting

quartz pine
#

badumps

upper current
#

I cant find it anywhere

bleak panther
#

some random thing by some random guy

pastel totem
#

oh god... written in go

bleak panther
#

aand it failed

upper current
#

Just use Coolify

#

Why did it fail?

bleak panther
#

shouldn't it be pnpm?

quartz pine
#

is the gh action up to date?

bleak panther
# upper current Just use Coolify

too complicated for an oracle cloud free tier vps to understand ๐Ÿ˜… also I like when stuff is contained just in a docker compose file I can manage myself

bleak panther
quartz pine
#

yeah, but where does "npm i" come from?

pastel totem
quartz pine
#

but doesnt your dockerfile look like that?

#

there is no npm

bleak panther
quartz pine
#

ah, I didnt see that in the github sry

#

but then you build it 2x no? ๐Ÿค”

bleak panther
#

github isn't building it right now

quartz pine
#

AH, okay, that makes sense then

bleak panther
#

github just creates an archive of the docs folder, dockerfile and compose file and then sends it to seelf

bleak panther
#

the publish workflow isn't

#

the build one is

#

publish if ran when a release is created

#

and I haven't been updating that for now

#

as build is what will actually run

quartz pine
#

ah, now I see, thanks for the clarification!

bleak panther
#

there is also duplicates of the compose and dockerfile now and the up to date ones are in the root, not in docs

quartz pine
#

ah, if you use the Dockerfile from the root you probably should adapt the paths:

COPY ./docs .
#

cause otherwise you copy the whole repo into the docs folder in the image and then try to run npm i in the root, which will not work because there is no packag.json

#

Hosting starlight with NGINX (and Apache2 - httpd) only shows main page

bleak panther
#

commit messages are getting better and better lol

pastel totem
#

oh no, he gave up with his messages ๐Ÿคฃ

quartz pine
#

no, the only reason I was helping out, the good commit messages ๐Ÿ˜…๐Ÿ˜‚

bleak panther
#

ok it still hasn't crashed with the npm stuff so I'm guessing it might actually be downloading packages now and also building it at some point?

#

HEY HO

#

alright, so it seems that compressing the dist directory and sending it to seelf for it to then unpack and just host doesn't work

#

but building it on the actual server works

#

well simpler anyway I guess (but github is a whole lot fasterr)

#

oh haha I removed the staging- prefix from the domain at some point and got confused why traefik would give this instead of its normal 404 all of a sudden but the domain is the same I have pages set to

quartz pine
#

ups ๐Ÿ˜…

bleak panther
#

ok but why did just sending the dist folder not work?

#

supposedly one of you do that though, no? (I am not keeping track of names and both your pfps are just the same shade of brown ๐Ÿ˜… )

quartz pine
#

I just build the website in gh action, build the docker image, push it to docker hub, have watchtower installed on my server, which regularly pulls the newest docker image, have everything behind traefik and watchtower runs the new containers

#

but that's how I used it, until I switched to Netlify, you could also try that

bleak panther
#

ehh I already have this stuff set up, I'm sticking with it

#

literally spent the whole day on this ๐Ÿ˜…

quartz pine
#

understandable, I kept my setup 2 years because I felt cool, until I switched to something even cooler (k3s, cilium, helm charts, argocd ๐Ÿ˜Ž)

#

unfortunately I now don't know what was actually not working, or what was the reason ๐Ÿค”, but nevertheless...

rustic meteorBOT
#
If your issue is resolved, please help by doing the following two steps:
  1. From the ellipses (3-dot menu) in the top-right corner of the post (not the first message), edit the tags to include the Solved tag.
  2. From the same ellipses, select Close Post.
    Your post will still be available to search and can be re-opened simply by replying in it. Closing a post moves it down with older posts, so we can more easily focus on issues that still need to be resolved.
    Thank you for your help!
quartz pine
#

after 300 messages ๐Ÿ™Œ

bleak panther
#

would trying to switch the hosting back to nginx be a good idea? you happen to know if either one is more light weight?

#

the nginx config had some compression stuff and things, would be a good thing to have?

quartz pine
bleak panther
#

or should I just stop torturing myself?

quartz pine
#

for today, I think we are good and can leave it, but it would be interesting so investigate further...

bleak panther
#

hmm wait but then the server has to do compression? not sure how well the oracle cloud free tier vps will like that ๐Ÿ˜…

#

yeah I'll leave it as is for now. No need to fix what isn't broken