I am trying to deploy an UI using nginx inside a docker container. In the same container my API’s are also hosted in Apache Tomcat . The API is supposed to run in 8080 port. I have configured my UI to run in 3000 port. The UI comes up at : http://localhost:3000 , however the UI also comes up at http://localhost:8080, which is wrong. I have been trying to debug these from last couple of days. Not able to understand the issue. request your help here. Attaching the nginx configuration for reference.
cat > /etc/nginx/conf.d/default.conf <<EOF
server {
listen 3000;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Serve React app and handle client-side routing
location / {
try_files \$uri /index.html;
}
location /api/ {
proxy_pass http://localhost:8080; # Replace with your backend app's internal port
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";
if (\$request_method = OPTIONS) {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";
return 204;
}
}
# Proxy Swagger UI requests to the backend application
location /swagger-ui/ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
# Cache static files (CSS, JS, images, etc.)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|ttf|woff|woff2|eot|otf|webp)$ {
expires max;
log_not_found off;
}
# Redirect all 404 errors to index.html
error_page 404 /index.html;
location = /index.html {
allow all;
}
}
EOF