Forum Discussion
Nginx is only redirecting to port 8080
I have a .net 8 solution multiple APIs and I'm using docker and Nginx to host the application. please find below the full details:
Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
...
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "xxx.Api/xxx.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "xxx.Api.dll"]
launchsettings.json
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"publishAllPorts": true,
"useSSL": true,
"sslPort": 4430,
"httpPort": 8080
}
nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
http{
server {
listen 80;
server_name domain;
port_in_redirect off;
location /api1 {
rewrite /api1(.*) $1 break;
proxy_pass http://api1: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;
}
location /api2 {
rewrite /api2(.*) $1 break;
proxy_pass http://api2:8081;
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;
}
}
docker-compose
version: '3.4'
services:
nginx:
image: nginx
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api1
- api2
api1:
image: ${DOCKER_REGISTRY-}api1:latest
container_name: api1
build:
context: .
dockerfile: api1.Api/Dockerfile
ports:
- "8080:8080"
api2:
image: ${DOCKER_REGISTRY-}api2:latest
container_name: api2
build:
context: .
dockerfile: api2.API/Dockerfile
ports:
- "8081:8081"
API1 that uses port 8080 loads normally but API2 that uses 8081 get error 502 gateway error.
If I switch the port on those same projects than API2 loads normally and API1 stops loading.
I've been trying all kinds of stuff over last 2 days and nothing seems to work.
Those same projects with the same configuration were working perfectly when I was using .net 6 with the same nginx version, but when I upgraded the project to .net 8 it broke.
I need your help and suggestions. Anything will be helpfull.
Does the api2 docker file expose port 8081?
also does launchsettings.json also have a version for 8081 port ?
- zamroni777Nacreous
a bit of out of topic, technically you can have api1 and api2 runs on same nginx instance.
these are some case study about going back from microservices to monolith:
amazon prime: https://www.primevideotech.com/video-streaming/scaling-up-the-prime-video-audio-video-monitoring-service-and-reducing-costs-by-90
https://world.hey.com/dhh/even-amazon-can-t-make-sense-of-serverless-or-microservices-59625580
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com