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.

Doploy behind a reverse proxy

See original GitHub issue

I’m moving from springfox to springdoc and I’m finding the following problem.

In the doc, you specify that the deploy urls are as follows:

http://server:port/context-path/swagger-ui.html
http://server:port/context-path/v3/api-docs 

In my case, the Spring Project is behind a reverse proxy, and I don’t have access to the base url of the server, so my urls look something like:

http://server:port/custom-path/context-path/swagger-ui.html
http://server:port/custom-path/context-path/v3/api-docs 

The problem is when I attempt to enter to the swagger-ui.html I see this error: image The point is, the web page is attempting to reach http://server:port/context-path/v3/api-docs instead of http://server:port/custom-path/context-path/v3/api-docs

As a last thing to mention, if I try to load http://server:port/custom-path/context-path/swagger-ui/index.html?url=/custom-path/context-path/v3/api-docs&validatorUrl= the page loads as expected

Is there a way to customize the path it loads by default? or maybe make it able to know the path where you are?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

9reactions
springdoccommented, Nov 17, 2019

Hi,

First of all, you need to make sure the following header is set in your reverse proxy configuration: X-Forwarded-Prefix For example, using apache 2, configuration

RequestHeader set X-Forwarded-Prefix "/custom-path"

Then, in your spring-boot application make sure your application handles this header: X-Forwarded-For. There are two ways to achieve this:

  • Since spring-boot 2.2, there is a new property to handle reverse proxy headers:
server.forward-headers-strategy=framework
  • Or you can add the following Bean to your application:
@Bean
ForwardedHeaderFilter forwardedHeaderFilter() {
   return new ForwardedHeaderFilter();
} 

Please don’t forget to give a feedback about which option resolved your issue.

1reaction
hectoryocommented, Nov 28, 2019

Hi, I’ve been able to fix this issue by adding the @Bean and adding the headers to my nginx proxy. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Set Up a Reverse Proxy (Step-By-Step for Nginx ...
A reverse proxy sits in front of a web server and receives all the requests before they reach the origin server. It works...
Read more >
What is a reverse proxy? | Proxy servers explained - Cloudflare
A reverse proxy protects web servers from attacks and can provide performance and reliability benefits. Learn more about forward and reverse proxies.
Read more >
Running Behind a Reverse Proxy - Sonatype Help
We provide some general guidance on how to configure common reverse proxy servers to work with Nexus Repository Manager Pro and Nexus Repository...
Read more >
Single-machine deployment with reverse proxy server
A reverse proxy server acts as an intermediary for client requests seeking resources from your ArcGIS Server site, adding extra security features to...
Read more >
What is a Reverse Proxy Server? - NGINX
A proxy server is a go‑between or intermediary server that forwards requests for content from multiple clients to different servers across the Internet....
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