Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

762
Vistas
How to serve static files (CSS, ...) with multiples Express app + NGINX as reverse proxy server

Context
I'm runnig multiples nodesJS/Express app on the same server with the same IP adress. I use Nginx to reverse proxy those apps and redirect it to subfolder adress (and not subdomain, i don't want to).
ex : http://123.0.0.1:8000 => http://monsite.com/Site1

Problem
My assets files (css, images, ...) do not load, I have a 404 error on those static files when the page loads. It happens only when I access the site via the proxy redirect http://monsite.com/Site1 and not when I use the IP adress : http://123.0.0.1:8000

I don't have this problem if a use the reverse proxy location from the root in the nginx conf : location / { but I want to access the site from a subfolder adress

My integration
Tree files:

var/www/html
          |Site1/
          |   |server.js
          |   |Views/
          |   |   |index.pug
          |   |Public/
          |   |   |Css/
          |   |   |   |Style.css
          |Site2/
          |....

nodejs server code

const PORT = 8000;
const HOSTNAME = 'www.monsite.com';

// Dependencies.
const express = require('express');
const http = require('http');

// Initialization.
var app = express();
var server = http.Server(app);

app.set('port', PORT);
app.set('view engine', 'pug');
app.set('views','Views');

app.use(express.static('Public'));

app.use('/', (request, response) => {
    response.render('index');
});

server.listen(PORT, HOSTNAME, function() {
    console.log(`STARTING SERVER ON PORT ${PORT}`);
});

index pug code

doctype html

html
  head
    title Site 1
    link(rel="stylesheet" href="/Css/style.css")

  body
    p Hello

nginx conf

server {
        listen 80;
        listen [::]:80;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html index.php;
        server_name www.monsite.com;

        location / {
                #Reserved for another site
        }

        location /Site1/ {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
                proxy_set_header X-NginX-Proxy true;

                proxy_redirect off;
                proxy_pass http://123.0.0.1:8000/;
        }
}

PS : I tried almost all the solutions and code I found searching for this problem and nothing worked, that's why I'm asking directly here. Thank you.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think the issue is with the url in the link tag to load the css, the url is invalid because the url is actually /Site1/Css/style.css.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda