Search code examples
nginxswagger-ui

Problem congifuring Nginx to visualize Swagger UI


I have a containerized dotnet service including swagger UI that I can locally run on localhost:7060/swagger/index.html.

I have a problem configuring nginx to point to it. Here is my weaplan.conf file that nginx detects

server {
    Listen 80;
    location /swagger {
         root /var/www/html/weaplanservices/DataHandlerAPI;
         proxy_pass http://127.0.0.1:7060;
         try_files $uri $uri/ /index.html;
    }    
}

Note: the project exists in the exact indicated root and the containerized app works correctly


Solution

  • I solved this issue by reconfiguring nginx this way to serve Swagger UI:

        server {
            Listen 80;
            location /swagger {
            root /var/www/html/weaplanservices/DataHandlerAPI;
            proxy_pass http://127.0.0.1:7060;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            }
        }