Я создал приложение nodejs для мобильного API, которое отлично работает на моем локальном сервере. Но когда я развернул его на живом сервере, я не получаю ответ.
У меня есть Ubuntu с apache2
Когда я звоню http://MY_IP_ADDRESS. Я получаю ответ от API, но когда я звонюhttp://MY_IP_ADDRESS/items/getcategories ошибка выдачи прокси
Server.js
var express = require('express');
var http = require('http');
var app = require('./app');
//const app = express();
const server = http.createServer(app);
const sio = require("socket.io")(server, {
handlePreflightRequest: (req, res) => {
const headers = {
"Access-Control-Allow-Headers": "Content-Type, Authorization",
"Content-type":"multipart/form-data",
"Access-Control-Allow-Origin": req.headers.origin, //or the specific origin you want to give access to,
"Access-Control-Allow-Credentials": true
};
res.writeHead(200, headers);
res.end();
}
});
server.listen(8080);
App.js
var express = require('express');
var app = express();
var cors = require('cors');
var bodyparser = require('body-parser');
var items = require('./api/items');
app.use(cors());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended:false}));
app.use("/items",items);
app.use(express.static(__dirname));
//if we are here then the specified request is not found
app.use((req,res,next)=> {
const err = new Error("Not Found");
err.status = 404;
next(err);
});
//all other requests are not implemented.
app.use((err,req, res, next) => {
res.status(err.status || 501);
res.json({
error: {
code: err.status || 501,
message: err.message
}
});
});
module.exports = app;
Код файла конфигурации моего виртуального хоста
<VirtualHost *:80>
ServerName MY_IP_ADDRESS
ProxyRequests off
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Мой код находится здесь
/var/www/html/lost_and_found/public_html
Ошибка при http://MY_IP_ADDRESS
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request
Reason: Error reading from remote server
Apache/2.4.18 (Ubuntu) Server at MY_IP_ADDRESS Port 80
Ошибка при http://MY_IP_ADDRESS/items/getcategories
{
"error": {
"code": 404,
"message": "Not Found"
}
}