The original post: /r/nginx by /u/Sarquamon on 2024-09-26 04:51:48.
Hello community, I'm currently currently having an issue when being redirected back from a SSO server. Also, I'm still a bit of an NGINX newbie so any support is much much appreciated. Thanks in advance! :D
A bit of context:
I'm working on creating a react app (using ts + vite) and I'm using NGINX to serve the bundle generated by vite.
Said application is using the react-router-dom package for routing the application, and in said router I have a route set up as: /redirect which as it implies, is the route which the SSO redirect back as a callback.
The issue
Whenever I open up the application in a docker container using openresty for serving the files it does find the actual index.html and redirects to the SSO, then when it comes back to /redirect from the SSO NGINX complains that the index.html is no where to be found.
What I've tried
- Made sure the routes in the server are correct.
- The root folder is correct under the nginx.conf file
- Default.conf file is deleted as everything will live under the nginx.conf file
- Updated the base property under the vite.config file
- Added a specific /redirect route under nginx
- Changed try_files for index directive
- Updated the root folder
- Read through posts, comments and replies accros multiple sites :')
- Prayed to the old gods and the new ones.
Project / NGINX config
The project as previously mentioned is a React app using vite and TS. I do have an auth wrapper which verifies the user is logged in from the start, this wrapper is responsible for redirecting to the SSO.
In the routes I have a /redirect
route which is when the SSO comes back (callback). The URL comes something like: https://localhost:8080/some/path/redirect#acc=...
and then... the app breaks.
Once I run the vite build
command, vite bundles everything and drops it in a /dist
folder. I copy just the contents of the folder and deploy it using an openresty container.
Since this is running under openresty container, I've set nginx.conf file as:
nginx.conf
pid /tmp/nginx.pid;
error\_log /dev/stdout;
events {
worker\_connections 1024;
}
pcre\_jit on;
worker\_processes auto;
http {
access\_log off;
error\_log /usr/local/openresty/nginx/logs/error.log debug;
include mime.types;
keepalive\_timeout 65;
default\_type application/octet-stream;
client\_body\_temp\_path /tmp/client\_temp;
proxy\_temp\_path /tmp/proxy\_temp\_path;
fastcgi\_temp\_path /tmp/fastcgi\_temp;
uwsgi\_temp\_path /tmp/uwsgi\_temp;
scgi\_temp\_path /tmp/scgi\_temp;
server {
listen 8080 ssl;
sendfile on;
proxy_read_timeout 300s; port_in_redirect off;
ssl_certificate /usr/local/openresty/nginx/conf/ssl/server.crt; ssl_certificate_key /usr/local/openresty/nginx/conf/ssl/server.key;
ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on;
large_client_header_buffers 4 32k;
root /usr/local/openresty/nginx/site/some/path;
location ~* .(?:css|js|map|jpe?g|gif|png|ico)$ { access_log /usr/local/openresty/nginx/logs/access.log combined; add_header Cache-Control public; add_header Pragma public; add_header Vary Accept-Encoding; expires 1M; }
location =/health { add_header Content-Type text/json; return 200 '{"Status": "Ok"}'; }
location / { try_files $uri $uri/ /index.html; }
}
}
The flow would be:
locahost:8080/some/path -> sso server -> localhost:8080/some/path/redirect#ac=...
Many many thanks in advance, any help is much appreciated.