我正在创建一个express.js应用程序,我称之为localhost。 简单的例子:
//https://example.com
router.get('/', function (req, res) {
require('http').request('http://localhost/api/?foo=bar', cb).
write('foo2=bar2').end();
resp.render('index');
});
我的快递应用程序在nginx下运行。 CONF:
server {
listen 443;
server_name example.com;
location /app {
root /var/www/node;
location ~ \.(svg|png|css|js) {
root /var/www/node/public;
try_files $uri =404;
}
include /etc/nginx/fastcgi_params;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://unix:/var/run/node/sails.sock;
proxy_redirect off;
}
}
server {
listen 80;
server_name localhost;
root /var/www/php/htdocs;
location / {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HOST $host;
fastcgi_param SCRIPT_FILENAME /var/www/php/htdocs$fastcgi_script_name;
}
}
我从http.request('http://localhost/api/?foo=bar')收到404错误。但是从控制台:curl'http://localhost/api/?foo=bar'得到了正确的答案。来自nginx的access.log的日志很清楚。在我的例子中是否可以访问localhost?有什么问题?