# Is anyone having the issue with Error 504?

**URL:** <https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562>\
**Category:** Server Side Swift with Vapor\
**Created:** [August 18, 2018, 3:36am UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562 "2018-08-18T03:36:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![thammaporn](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thammaporn/32/81494_2.png) [@thammaporn](https://forums.kodeco.com/u/thammaporn)\
**Post date:** [August 18, 2018, 3:36am UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/1 "2018-08-18T03:36:42Z")

</div>

Is anyone having the issue with 504 Gateway time-out or Is it just my network on the server?  
This doesn’t happened in localhost on my pc.

I have get this error when requested the page through Token Authentication(after /login ).  
My project is running on Nginx and I tried to config the proxy server but it doesn’t work.

Much appreciated if anyone can share how to fix the problem.

---

<div class="post-metadata">

**Author:** ![omaralbeik](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/omaralbeik/32/91929_2.png) [@omaralbeik](https://forums.kodeco.com/u/omaralbeik)\
**Post date:** [August 23, 2018, 6:20pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/2 "2018-08-23T18:20:13Z")

</div>

I’m having the exact same problem with Vapor and nginx

/api/users/ (ok)  
/api/users/id (504 error)

It works on localhost though 🤔

---

<div class="post-metadata">

**Author:** ![thammaporn](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thammaporn/32/81494_2.png) [@thammaporn](https://forums.kodeco.com/u/thammaporn)\
**Post date:** [August 26, 2018, 6:25am UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/3 "2018-08-26T06:25:10Z")

</div>

Hello @omaralbeik ,

After I rechecked my api both on localhost at my pc and Nginx on the cloud server.  
For my case, It work properly.

But When I protect with CSRF tokens in Chapter 20 “Web Authentication” below code . For my case ,It happened “504” only on the cloud server ,but not on the localhost at my pc .

_**let protectedRoutes = authSessionRouters.grouped(RedirectMiddleware(path:“/login”))**_  
**_protectedRoutes.get(“acronyms”,“create”,use: createAcronymHandler)_**

So far I tried to debug from Nginx log file . But still don’t catch any cause .

---

<div class="post-metadata">

**Author:** ![omaralbeik](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/omaralbeik/32/91929_2.png) [@omaralbeik](https://forums.kodeco.com/u/omaralbeik)\
**Post date:** [August 26, 2018, 6:51am UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/4 "2018-08-26T06:51:07Z")

</div>

In my case, I had a `User` object that owns `Todo` children, and I use Token auth.  
the problem is getting a `Todo` by its id is working only on localhost, but not Nginx  
After a few hours of debugging, I fixed it by getting the children from the authenticated user and query over them.

This works:

> <https://github.com/omaralbeik/VaporTodos-API/blob/93484d2b7d17989ff881a5f117ebe9911845cde6/Sources/App/Controllers/TodoController.swift#L43>

This does not:

> <https://github.com/omaralbeik/VaporTodos-API/blob/fa628deddbf52ebd7d601a895765fe3794e9483e/Sources/App/Controllers/TodoController.swift#L26>

Still, I have no idea why this is the case 😅

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [August 29, 2018, 3:05pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/5 "2018-08-29T15:05:21Z")

</div>

Is Nginx definitely forwarding the authentication headers?

---

<div class="post-metadata">

**Author:** ![thammaporn](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thammaporn/32/81494_2.png) [@thammaporn](https://forums.kodeco.com/u/thammaporn)\
**Post date:** [September 1, 2018, 2:30pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/6 "2018-09-01T14:30:14Z")

</div>

@0xtim

Hello ,  
Did you mean forward “Bearer Token” to proxy header?  
My Nginx.conf is look like below.  
Very appreciated if you could share about how to add the authentication header into the Sever block .

* * *

try\_files $uri @proxy;  
location @proxy {  
proxy\_set\_header HOST $host;  
proxy\_set\_header X-Forwarded-Proto $scheme;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass [http://localhost:8080](http://localhost:8080);  
proxy\_redirect http:// https://;

…

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [September 1, 2018, 2:44pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/7 "2018-09-01T14:44:56Z")

</div>

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

---

<div class="post-metadata">

**Author:** ![thammaporn](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thammaporn/32/81494_2.png) [@thammaporn](https://forums.kodeco.com/u/thammaporn)\
**Post date:** [September 18, 2018, 7:03pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/8 "2018-09-18T19:03:02Z")

</div>

After I run command " update vapor " then rebuild the project.  
There are no issue regarding the error 504 .

Thanks vapor team to fix the problem.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [September 18, 2018, 9:03pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/9 "2018-09-18T21:03:22Z")

</div>

@thammaporn Thank you for sharing the solution - much appreciated!

---

<div class="post-metadata">

**Author:** ![axlroach](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@axlroach](https://forums.kodeco.com/u/axlroach)\
**Post date:** [September 26, 2018, 4:06pm UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/10 "2018-09-26T16:06:21Z")

</div>

Hi all – Sorry, I think I’m missing something here. What was the solution to this issue? I’m having exactly the same problem. Is there an nginx config I need to change?

I have in my boot router:

let tokenAuthGroup = userRoutes.grouped(tokenAuthMiddleware, guardAuthMiddleware)

tokenAuthGroup.get(use: list)  
tokenAuthGroup.get(User.parameter, use: get)

both work locally on my mac, but only list works on the server behind nginx.

The get function is:

func get(\_ req: Request) throws → Future\<User.Public\> {  
return try req.parameters.next(User.self).convertToPublic()  
}

Thanks so much!

---

<div class="post-metadata">

**Author:** ![axlroach](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@axlroach](https://forums.kodeco.com/u/axlroach)\
**Post date:** [September 27, 2018, 7:44am UTC](https://forums.kodeco.com/t/is-anyone-having-the-issue-with-error-504/46562/11 "2018-09-27T07:44:23Z")

</div>

Sorry, I wasn’t following the ‘update vapor’ comment from before. I ran ‘vapor update -y’ and that seems to have fixed the issue. FYI - I initially had an error when attempting the update, so I removed the Package.resolved file and then removed the .build directory. Then ‘vapor update -y’ ran with no error. I then reissued ‘swift build -c release’ and restarted my vapor app.

Hope this helps someone.

Thanks all!
