title: Nginx Microservices Authentication
body: <p>What's the best practice to build microservices authentication over Nginx?</p>
  
  <p>At the moment I have the next reverse-proxy service</p>
  
  <pre><code>server {
      listen 80;
      listen [::]:80;
  
      server_name sspay.local;
  
      location /service/passport/ {
          proxy_pass http://passport-service:3000/;
          proxy_redirect off;
          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-Host $server_name;
      }
  }
  </code></pre>
  
  <p>For example I want to create "user-serivce" which will be giving information about users. And I want it to give information about current user for ordinary user and information about all users for admins.</p>
  
  <p>For this opportunity passport service gives JWT token that contains rights information for user.</p>
  
  <p>So how I can create "a middleware" inside nginx which will do requests to "passport-service" to check if current JWT token has rights to access specified routes (ex., "/service/users/{id}")</p>