October 07, 2023 07:45PM
Hi,
set up nginx in this way
1) it hosts some static files
2) it reverse proxies to a nodejs/express application
3) it revers proxies to a nodejs/express public directory that stores static images

This is the config I currently have.


server {

listen 8080 default_server;
listen [::]:8080 default_server;

## BACKEND
location ~ ^\/api\/v\d{1,}\/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://localhost:9000;
}

## IMAGES
location /images/profiles/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://localhost:9000;
}

## FRONTEND
location / {
root /usr/share/nginx/html;
index index.html index.htm;

# to redirect all the requests to index.html,
# useful when you are using react-router
try_files $uri $uri/ /index.html;
gzip_static on;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}
}


1) I would like any url like http://mydomain.com/api/v1 or http://mydomain.com/api/v222 to go to the node server
2) I would like any url like http://mydomain.com/images/profiles/me.jpg to go to the node server where express will auto handle statically requested content
3) I would like any other url to be handled by ngnix, i have a couple static files stored in the html folder so any other url not handles by 1 or 2 above would be handled by 3 and either load a static content or give an error

Only 1 ) seems to be working any other url is giving a route does not exist error (from the express server).

Do my locations look ok for what i would like?
Subject Author Posted

location blocks

janusqa October 07, 2023 07:45PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 166
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready