question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger redirects to port 8080 when using BASE_URL

See original GitHub issue
Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3
Which Swagger-UI version? 3.13.1/latest
How did you install Swagger-UI? With the docker image, behind an nginx reverse proxy
Which browser & version? Chrome, Safari…
Which operating system? MacOS X

Configuration (browser query string, constructor, config.yaml)

Docker-compose.yml

version: '3.5'

services:
  gateway:
    build: ./nginx
    ports:
      - "80:80"
      - "443:443"
    links:
      - swaggerui

  swaggerui:
    image: swaggerapi/swagger-ui
    restart: always
    environment:
      - BASE_URL=/swagger

nginx.conf

# Documentation server
server {
    listen 443 ;

    include /etc/nginx/proxy.conf;
    include /etc/nginx/ssl.conf;

    location ^~ /swagger {
        proxy_pass              http://swaggerui:8080;
    }
}
curl -v http://doc.dev/swagger

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to doc.dev (127.0.0.1) port 80 (#0)
* Server auth using Basic with user 'test'
> GET /swagger HTTP/1.1
> Host: doc.dev
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Wed, 28 Mar 2018 10:50:30 GMT
< Content-Type: text/html
< Content-Length: 185
< Connection: keep-alive
< Location: http://doc.dev:8080/swagger/
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
* Connection #0 to host doc.dev left intact

BUT when I add a final slash

curl -v http://doc.dev/swagger/
# I get the swagger app

Expected Behavior

It should work for http://doc.dev/swagger and http://doc.dev/swagger/ (with final slash) as well

Current Behavior

When not adding a final slash, we are redirected to 8080

Context

I have to explain this strange behavior to my teammates and to take care of the links I send.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:18
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
webroncommented, Oct 22, 2019

@danielpsf please don’t kill yourself over software, it’s not worth it.

2reactions
shockeycommented, Oct 24, 2018

@maximelebastard, I think this is an issue with your proxy setup - it should handle rewriting Swagger UI’s URLs based on what your user is seeing.

Per this Server Fault answer, can you try changing your proxy_pass directive to:

        proxy_pass              http://swaggerui:8080/;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Swagger automatically adds :80 to the service url when ...
I'm getting this strange behavior when the path is specified without an explicit port. I don't want to use :80 explicitly because as...
Read more >
how to do friendly base url for swagger 2.8.0 - Stack Overflow
I'm trying to change base access url for API documentation. The url is "http://localhost:8080/swagger-ui.html". I want to get something like " ...
Read more >
API Host and Base Path - Swagger
REST APIs have a base URL to which the endpoint paths are appended. The base URL is defined by schemes , host and...
Read more >
Using OpenAPI and Swagger UI - Quarkus
This guide explains how your Quarkus application can expose its API description through an OpenAPI specification and how you can test it via...
Read more >
how to do friendly base url for swagger 2.8.0-Springboot
In my case, I can't use any resource redirect as swagger must be accessible as locally as on google cloud by match path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found