0

I have a fullstack node express which serve static files and the api running on port 5000.

my nginx config is :

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

        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name mycoolserver.com;

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

server {
       listen 80;
       listen [::]:80;
       
       server_name fancyapp.mycoolserver.com;

       location / {
         proxy_pass http://127.0.0.1:5000/;
       }
}

I can load the index.html at http://fancyapp.mycoolserver.com but the css and js from this file failed to be loaded.

If I try to access some of the api, eg: http://fancyapp.mycoolserver.com/birds, it's working.

I've read countless stackoverflow posts and google it for days without success.

2
  • You forgot the root directive. Commented May 28, 2021 at 11:46
  • it was intentional to omit root, because it's my node express which serves the static content. I just Nginx to proxy everything to my node app which serves the frontend and the backend. Commented May 28, 2021 at 13:04

1 Answer 1

0

Most likely your site URL is not set correctly in your application.

I don't see any point to serve static assets via your backend application. You don't get practically any benefit from having nginx in the front...

1
  • I finally serve static assets from Nginx and use it as a reverse proxy only for the backend. Thanx for your answers. Commented May 29, 2021 at 13:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.