Hi I'm running Laravel on NGINX server and I would like to use NGINX reverse proxy capability as an API gateway for my Laravel and other node API application. Here are my configurations:
Application URL: staging-app.example.com
Application API Endpoint: staging-app.example.com/api
API Gateway URL: api.example.com
What I want to do, is to redirect all API requests api.example.com/staging-app
to staging-app.example.com/api
. I have succeed in redirecting the API request, but somehow the Authorization header
is not passed along to the proxy pass resulting in 401 unauthorized while other header do get passed along.
Here is my current api.example.com
nginx config:
server {
server_name api.example.com;
location /staging-app {
rewrite ^/staging-app/(.*)$ /$1 break;
proxy_pass http://staging-app.example.com/;
}
location /test {
rewrite ^/test/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:3333/;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = api.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name api.example.com;
return 404; # managed by Certbot
}
and for my laravel application, I use the configuration given from Laravel themselves
Update 1: I tried adding proxy_set_header Test testingvalue
in the location block directly, but it doesn't seems to work either