A
A
Artur Nuraev2021-10-23 23:31:30
Nginx
Artur Nuraev, 2021-10-23 23:31:30

How to configure L5 Swagger to work with nginx proxy_pass?

There is an nginx configuration that, depending on the parameter in the URL, redirects to the desired bec

location ~ ^/main-back/ {
proxy_pass http://main-back:80;
rewrite /main-back/(.*) /$1 break;
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;
}

The back works on laravel. Worth darkaonline/l5-swagger and zircote/swagger-php. I put all the annotations, everything works locally. However, when I run on the server with nginx proxy_pass, then on the page with swagger I see errors in the paths to the css and js files https://take.ms/W44M1 i.e. it does not put /main-back/ in the file path. What I didn’t try, and set up l5-swagger.php, and tried various nginx configurations, tried to set redirects in .htaccess

The task is to follow the link mysit.com/main-back/api-doc, the documentation on the back was opened the side that is taken from the inner container. The front part runs on a different container than the back part.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2021-10-23
@karabanov

You're cutting off that part of the way withrewrite /main-back/(.*) /$1 break;

tried tried to register redirects in .htaccess

Nginx does not support .htaccess, this is done so that the configuration is readable and predictable.

A
Artur Nuraev, 2021-10-24
@Fayst563

In general, I decided this:

location /main-back/ {
    proxy_pass          http://main-back:80/main-back/;
    rewrite /main-back/(.*) /$1 break;
    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto $scheme;
    location /main-back/docs {
      rewrite /main-back/(.*) /main-back/$1 break;
      proxy_pass          http://main-back:80/main-back/docs;
    }
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question