【发布时间】:2017-12-24 08:14:17
【问题描述】:
我用Express框架写了一个Node.js服务器项目。在localhost上没问题。但是当我在远程服务器上构建时出现了一些问题。(centos 6.5; ngnix 1.11.6; express 4.14.1; node 6.9。 5)
-
这是 nginx.conf。
listen 80; server_name www.cheeseyu.cn cheeseyu.cn; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://127.0.0.1:3009; proxy_redirect off; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css|woff|ttf|TTF|svg)$ { root /home/www/blog; if (-f $request_filename) { expires 100d; break; } } error_page 405 =200 @405; location @405 { proxy_method GET; proxy_pass http://static_resource; } #error_page 404 /404.html; -
有xhr的信息。 enter image description here enter image description here
-
它是 node.js。
var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');
var routes = require('./routes');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.all('', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "");
res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
routes(app);
app.set('port', process.env.PORT || 3009);
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
所以我的问题是:
- 一个。为什么状态是200,即使我停止了后台服务器?
- 乙。为什么响应数据是 html(内容是 index.html)?
- c。为什么状态仍然是 405,当我使用帖子时?我尝试过任何 我找到的方法。
- d.为什么状态为 200,但请求后不要使用“.then”,而是使用 '.catch'?
- e. nginx代理如何表达(node.js)?(我认为最重要的问题是 nginx 没有将请求代理到节点服务器。)
如需了解回复详情,请访问cheeseyu.cn
谢谢你的帮助:)
【问题讨论】:
标签: node.js express nginx proxy