# Use nginx to add Authentication to any Application

**URL:** <https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921>\
**Category:** Developer Blog Comments\
**Created:** [August 28, 2018, 12:40am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921 "2018-08-28T00:40:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 28, 2018, 12:40am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/1 "2018-08-28T00:40:44Z")

</div>

[Use nginx to add Authentication to any Application](https://developer.okta.com/blog/2018/08/28/nginx-auth-request)

This tutorial will show you how to use the nginx auth\_request module to protect any application running behind your nginx server with OAuth, without writing any code!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 4, 2018, 11:13am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/2 "2018-09-04T11:13:58Z")

</div>

**kobi.s**

Looks like a very cool solution, i tried it according to the instructions here but it always redirect the traffic to Github although i only left the okta config in the YML file .  
Any thoughts ?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 15, 2018, 9:55am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/3 "2018-12-15T09:55:36Z")

</div>

**Gavin V**

This is a great post.   
One thing doesn’t make sense and took me some time to figure out  
You have 2 domains [stats.avocado.lol](http://stats.avocado.lol "stats.avocado.lol") and [login.avocado.lol](http://login.avocado.lol "login.avocado.lol"). When i copied this configuration i noticed that the browser would not send the cookie when accessing [stats.avocado.lol](http://stats.avocado.lol "stats.avocado.lol") since it was acquired when accessing [login.avocado.lol](http://login.avocado.lol "login.avocado.lol"). This caused a JWT not found error in lasso and looped back to login endlessly. As i understand this would be cross site sharing of the cookie. I also believe that this is possible but would need further config not detailed in this article (set cookie: domain1 domain2 etc perhaps)…

Great article however and very much appreciate you time to share this.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 15, 2018, 10:20am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/4 "2018-12-15T10:20:42Z")

</div>

**Gavin V**

Just to follow up, i managed to get this working by setting the cookie name in the config.yml to be the root domain. It will then allow the browser to submit the cookie when accessing all sub domains  
cookie:  
domain: [avacado.lol](http://avacado.lol "avacado.lol")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 14, 2019, 2:57pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/5 "2019-02-14T14:57:12Z")

</div>

**abhijeetkpawar**

Is there any similar blog for Apache?

If not, it would be helpful if one is written.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [April 3, 2019, 10:09pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/6 "2019-04-03T22:09:16Z")

</div>

**Jasbir B**

I like this idea. But I noticed that the details are out of date so it is hard to figure out how to get it working.

First, the “Create New Application” page is different now. It asks you to fill in different information than what is in the article.

Also, Lasso has been deprecated. You can try vouch-proxy instead, but the settings are different. So you have to combine the changes on the vouch-proxy github page with the changes above.

I tried to set them in a reasonable way, but it never redirected to the Okta login. Nothing in the logs either

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [April 6, 2019, 2:16am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/7 "2019-04-06T02:16:26Z")

</div>

**krishnam**

Hi @gavin\_vickers:disqus - is it possible for you to share your config.yaml. I am having similar problem after authentication cookie is set, it goes into a loop. I tried the cookie: domain as you suggested but that is also not helping in my case. Anything on the ngnix conf that you have put to avoid this problem.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 12, 2019, 5:42pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/8 "2019-08-12T17:42:04Z")

</div>

**Dave B**

Does this require API Access Management to be enabled on the Otka server? I’m getting “The requested feature is not enabled in this environment.” when I try to login from my app.   
400: Bad Request  
BAD REQUEST

Your request resulted in an error.  
Go to Homepage  
Identity Provider: Unknown  
Error Code: server\_error  
Description: The requested feature is not enabled in this environment.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 14, 2019, 7:36pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/9 "2019-08-14T19:36:59Z")

</div>

**Matt Raible**

Hello Dave,

I believe this is because you don’t have an Okta developer account. Orgs created through [developer.okta.com](https://developer.okta.com "https://developer.okta.com") have the `default` custom Authorization Server enabled. Free Trial workforce orgs do not, nor do Enterprise workforce orgs.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 14, 2019, 11:10pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/10 "2019-08-14T23:10:50Z")

</div>

**Dave B**

Hi Matt,

actually it turns out there is a work around, [https://support.okta.com/he…](https://support.okta.com/help/s/article/400-error-on-authentication-to-Okta-using-OIDC "https://support.okta.com/help/s/article/400-error-on-authentication-to-Okta-using-OIDC") you just have to remove the /default from the oauth2 urls in the vouch config, and it seems to work. ( It moved my problem farther along anyway. )

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 14, 2019, 11:16pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/11 "2019-08-14T23:16:26Z")

</div>

**Matt Raible**

Yes, this is certainly an option if you don’t require an access token for a custom API and only need it for Okta resources.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [December 30, 2019, 11:55am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/12 "2019-12-30T11:55:46Z")

</div>

**Sam D. Lee**

OAuth2 grant type client\_credentials and password can be used for scenario, protecting company’s APIs from external access. I am wondering if Vouch can be used in this use case and whether the same settings for vounch in nginx.conf be used?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [July 8, 2020, 9:47am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/13 "2020-07-08T09:47:37Z")

</div>

**Rakesh**

Hi @kobi\_s i am also facing the same issue. Did u got any resolution.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [July 9, 2020, 11:12am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/14 "2020-07-09T11:12:53Z")

</div>

**Rakesh**

Hi Team,  
I am getting the below error after successful authentication.

{“level”:“error”,“ts"1594280010.3651514,“msg”:”/auth Error while retreiving user info after successful login at the OAuth provider: Post “[https://dev-813551.okta.com…](https://dev-813551.okta.com/oauth2/default/v1/token "https://dev-813551.okta.com/oauth2/default/v1/token")”: dial tcp: lookup [dev-813551.okta.com](http://dev-813551.okta.com "dev-813551.okta.com") on 10.65.0.33:67: no such host"}

[dev-813551.okta.com](http://dev-813551.okta.com "dev-813551.okta.com") is not reachable from my vouch-proxy server. if i have to access this then i have to use an outgoing proxy.

Please let me know how to set outgoing proxy in vouch server so that it can make request to my okta dev account.

Any help will be appreciated.

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [July 13, 2020, 4:04pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/15 "2020-07-13T16:04:53Z")

</div>

**Joseph Fitzgerald**

Didn’t you run into problems with $request\_uri not being urlencoded? If the original request contained “?” and “&” I think it would throw off your solution.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 3, 2020, 5:58pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/16 "2020-08-03T17:58:23Z")

</div>

**Matt Raible**

I’m not sure how to do this as I’ve never used vouch-proxy server before. I’d suggest you ask this question on Stack Overflow so more Nginx experts see it.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 3, 2020, 6:10pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/17 "2020-08-03T18:10:59Z")

</div>

**aaronpk**

The config file format has changed from what is described in this post, so make sure you’re following the instructions in the project’s readme!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 3, 2020, 6:16pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/18 "2020-08-03T18:16:25Z")

</div>

**aaronpk**

Yes, if you need to handle URLs with a query string then you’ll have to URL encode that parameter using something like [https://github.com/openrest…](https://github.com/openresty/set-misc-nginx-module#set_escape_uri "https://github.com/openresty/set-misc-nginx-module#set\_escape\_uri"). This isn’t an issue for majority of my deployments.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 4, 2020, 9:00am UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/19 "2020-08-04T09:00:34Z")

</div>

**suresh-rasa**

Hi Aaron, Adding $auth\_user satisfies authentication. How do I check this user has this role or group to access this application? Can Nginx pass role or group information to downstream applicationn, python (flask api’s), so the group or role can also be validated.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 22, 2020, 11:38pm UTC](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921/20 "2020-08-22T23:38:09Z")

</div>

**Andrzej Sydorko**

Got the login part working but struggling with logging out. I’m seeing “/logout deleting session” in the vouch log but can still access the application/web page.

[Next page](https://devforum.okta.com/t/use-nginx-to-add-authentication-to-any-application/16921.md?page=2)
