【发布时间】:2014-11-08 20:22:12
【问题描述】:
我刚刚在 Ubuntu 14.04 上创建了一个 MongoDB 实例,并通过username:password. 进行身份验证
我创建的用户是这样的:
{
"_id" : "myDatabase.myUser",
"user" : "myUser",
"db" : "myDatabase",
"roles" : [ { "role" : "readWrite", "db" : "myDatabase" } ]
}
我在用 Node.js(使用 Express 和 Mongoose)编写的 REST API 上使用的 URI 字符串如下:
mongodb://myUser:password@localhost:27017/myDatabase
连接正常,GET 方法工作正常,但是当我使用POST 方法时,例如通过电子邮件/密码注册,响应是:
Status Code:405 Not Allowed
有什么想法吗?提前致谢!
仅供参考:我使用 Nginx 作为反向代理和前端的 Web 服务器(AngularJS 应用程序),配置是:
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/nginx.access.log;
error_log /var/log/nginx/nginx.error.log;
location / {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
root /usr/share/www;
try_files $uri $uri/ /index.html =404;
}
location /api/v1 {
proxy_set_header "Access-Control-Allow-Origin";
proxy_set_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, PUT, DELETE";
proxy_set_header "Access-Control-Allow-Headers" "X-Requested-With,Accept,Content-Type, Origin";
proxy_pass http://127.0.0.1:3000/api/v1;
proxy_buffering on;
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_set_header origin "http://example.com";
}
}
【问题讨论】:
标签: node.js mongodb authentication nginx privileges