部署时我无法让 nodejs 在 apache 上工作
I can't get nodejs to work on apache when deploying
我听说可以使用反向代理将请求从 apache 重定向到 nodejs 服务器。我尝试这样做,但没有用。我有一个 404 错误。这是我的 Apache 配置:
<VirtualHost WW.XX.YY.ZZ:80>
SuexecUserGroup "#1004" "#1004"
ServerName api.example.com
ServerAlias www.api.example.com
ServerAlias mail.api.example.com
ServerAlias webmail.api.example.com
ServerAlias admin.api.example.com
DocumentRoot /home/example/domains/api.example.com/public_html
ErrorLog /var/log/virtualmin/api.example.com_error_log
CustomLog /var/log/virtualmin/api.example.com_access_log combined
ScriptAlias /cgi-bin/ /home/example/domains/api.example.com/cgi-bin/
ScriptAlias /awstats/ /home/example/domains/api.example.com/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /home/example/domains/api.example.com/public_html>
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
</VirtualHost>
我的 nodejs 服务器在本地运行,所以我认为这不是问题,但我分享它以防万一:
const express = require("express");
const cors = require("cors");
const fs = require('fs');
const http = require('http');
const https = require('https');
const privateKey = fs.readFileSync('./ssl.key', 'utf8');
const certificate = fs.readFileSync('./ssl.cert', 'utf8');
var credentials = {key: privateKey, cert: certificate};
const app = express();
app.use(cors());
app.use(express.json())
require("./routes/wordpress.routes.js")(app);
require("./routes/entries.routes.js")(app);
// set port, listen for requests
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(8080);
httpsServer.listen(8443);
我做错了什么?
固定成这样:
ProxyPass "/" "http://localhost:8080/"
ProxyPassReverse "/" "http://localhost:8080/"
我听说可以使用反向代理将请求从 apache 重定向到 nodejs 服务器。我尝试这样做,但没有用。我有一个 404 错误。这是我的 Apache 配置:
<VirtualHost WW.XX.YY.ZZ:80>
SuexecUserGroup "#1004" "#1004"
ServerName api.example.com
ServerAlias www.api.example.com
ServerAlias mail.api.example.com
ServerAlias webmail.api.example.com
ServerAlias admin.api.example.com
DocumentRoot /home/example/domains/api.example.com/public_html
ErrorLog /var/log/virtualmin/api.example.com_error_log
CustomLog /var/log/virtualmin/api.example.com_access_log combined
ScriptAlias /cgi-bin/ /home/example/domains/api.example.com/cgi-bin/
ScriptAlias /awstats/ /home/example/domains/api.example.com/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /home/example/domains/api.example.com/public_html>
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
</VirtualHost>
我的 nodejs 服务器在本地运行,所以我认为这不是问题,但我分享它以防万一:
const express = require("express");
const cors = require("cors");
const fs = require('fs');
const http = require('http');
const https = require('https');
const privateKey = fs.readFileSync('./ssl.key', 'utf8');
const certificate = fs.readFileSync('./ssl.cert', 'utf8');
var credentials = {key: privateKey, cert: certificate};
const app = express();
app.use(cors());
app.use(express.json())
require("./routes/wordpress.routes.js")(app);
require("./routes/entries.routes.js")(app);
// set port, listen for requests
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(8080);
httpsServer.listen(8443);
我做错了什么?
固定成这样:
ProxyPass "/" "http://localhost:8080/"
ProxyPassReverse "/" "http://localhost:8080/"