【问题标题】:Hosting a JWT authentication app on my server在我的服务器上托管 JWT 身份验证应用程序
【发布时间】:2017-06-22 05:53:01
【问题描述】:

我遵循以下教程 https://jonathanmh.com/express-passport-json-web-token-jwt-authentication-beginners/ 进行 JWT 身份验证。完整代码可在https://gist.github.com/JonathanMH/6bd82c0954fb8f21a837ce281da4265a 查看。

在我的本地机器上,应用程序运行良好,但我希望能够将它部署在运行带有 NGINX 的 Ubuntu 服务器的虚拟专用服务器上。

我的 NGINX 配置应该如何使其在服务器上运行?目前看来我遇到了 CORS 问题或其他问题。

【问题讨论】:

    标签: express nginx jwt passport.js


    【解决方案1】:

    经过长时间的搜索,我找到了解决方案。我不得不将 cors npm 包添加到我的 app.js 文件中。

    然后我不得不更改“api”调用以使用服务器的公共 IP 地址(在本教程的 jwt-vanilla.js 中),因为我使用的是基于 OpenStack 环境的服务器还必须允许 OpenStack 中的 3000 端口。 (有关安装 cors 的更多详细信息,请参阅以下视频 (https://egghead.io/lessons/angularjs-client-setup-for-jwt-authentication)

    我使用了以下 nginx 配置:

    server {
        listen 80;
        server_name yourdomain.com;
    
        location /{
             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;
             proxy_pass    http://127.0.0.1:3000/;
        }
    }
    

    所以现在我正在运行 nginx 并在 app.js 位置的服务器上(端口 3000)我启动了“node app.js”,而在公共文件夹中我启动了 http-server(npm install http -server -g) 在 8080 上运行。

    【讨论】:

    • 它适用于所有 spring ouath2 客户端配置。谢谢。
    猜你喜欢
    • 2017-09-12
    • 2017-08-19
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多