How to setup Nginx with Auth0?

邮差的信 提交于 2020-05-29 07:21:07

问题


I got an app running in port 3000.

this app is working behind a reverse proxy such as:

server {
    listen 80;
    server_name myapp;

    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

so, everytime I access to my site, it will serve to localhost the content from port 3000, and it's working ok.

The problem is after the auth0 authentication, when the user is authenticated it keeps redirecting to localhost:3000/#, how can I make it work to localhost?

this is my Nginx config file:

server {
    listen 80;
    server_name myapp;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
    }

    location /generic_oauth/ {
        proxy_pass http://127.0.0.1:3000;
    }
}

callback is localhost/login/generic_oauth

my auth0 settings callback is: http://localhost:3000/login/generic_oauth

if I change my auth0 callback to http://localhost/login/generic_oauth

got the error:

the callback must be http://localhost:3000/login/generic_oauth

sorry for my bad english


回答1:


The application has to know what domain name to use on the URLs it issues. nginx may also need to do some rewriting.

Add an X-Forwarded-Host header, and potentially a proxy_redirect directive, as per instructions here

https://www.nginx.com/resources/wiki/start/topics/examples/likeapache/



来源:https://stackoverflow.com/questions/49143489/how-to-setup-nginx-with-auth0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!