# 403 forbidden behind nginx

**URL:** <https://forums.swift.org/t/403-forbidden-behind-nginx/53818>\
**Category:** Vapor\
**Created:** [December 2, 2021, 3:59am UTC](https://forums.swift.org/t/403-forbidden-behind-nginx/53818 "2021-12-02T03:59:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhao\_Xin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/zhao_xin/32/8394_2.png) [@Zhao\_Xin](https://forums.swift.org/u/Zhao_Xin)\
**Post date:** [December 2, 2021, 3:59am UTC](https://forums.swift.org/t/403-forbidden-behind-nginx/53818/1 "2021-12-02T03:59:12Z")

</div>

I can test my vapor sample under localhost:8080, but with nginx proxy on 80 to 127.0.0.1:8080, the page keeps on showing 403 forbidden. What should I do now?

```
root /home/zhaoxin/vapor/hello;

```

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [December 2, 2021, 4:48am UTC](https://forums.swift.org/t/403-forbidden-behind-nginx/53818/2 "2021-12-02T04:48:46Z")

</div>

`localhost` is not equivalent to `127.0.0.1`, you should keep your Vapor app and Nginx proxy aligned.

---

<div class="post-metadata">

**Author:** ![Zhao\_Xin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/zhao_xin/32/8394_2.png) [@Zhao\_Xin](https://forums.swift.org/u/Zhao_Xin)\
**Post date:** [December 2, 2021, 5:32am UTC](https://forums.swift.org/t/403-forbidden-behind-nginx/53818/3 "2021-12-02T05:32:02Z")

</div>

Somehow the sample on the official site didn't work.

[Vapor: Deploy → Nginx](https://docs.vapor.codes/4.0/deploy/nginx/) didn't work.

But I followed another article and this worked.

> **[Deploy a basic Vapor app with Nginx and Supervisor](https://medium.com/@goelankit/deploy-a-basic-vapor-app-with-nginx-and-supervisor-1ef303320726)**
>
> Swift on server: Learn to deploy a vapor app and setup Nginx and Supervisor.

So I guess the nginx conf file was not correct.

----Here is the working conf I used----

```swift
server {
    server_name vapor.parussoft.com;
    listen 80;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    try_files $uri @proxy;
    location @proxy {
        proxy_pass http://127.0.0.1:8080;
        proxy_pass_header Server;
        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_pass_header Server;
        proxy_connect_timeout 3s;
        proxy_read_timeout 10s;
    }
}

```

-- comparing with the sample---

```swift
server {
    server_name hello.com;
    listen 80;

    root /home/vapor/Hello/Public/;

    location @proxy {
        proxy_pass http://127.0.0.1:8080;
        proxy_pass_header Server;
        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_pass_header Server;
        proxy_connect_timeout 3s;
        proxy_read_timeout 10s;
    }
}

```

---

<div class="post-metadata">

**Author:** ![vine](https://avatars.discourse-cdn.com/v4/letter/v/6bbea6/32.png) [@vine](https://forums.swift.org/u/vine)\
**Post date:** [December 2, 2021, 5:47am UTC](https://forums.swift.org/t/403-forbidden-behind-nginx/53818/4 "2021-12-02T05:47:39Z")

</div>

This is deploy article

[https://www.jianshu.com/p/cb0b9f49544e](https://www.jianshu.com/p/cb0b9f49544e)
