我想在远程
NodeJS
服务器上部署我的 Apache
应用程序,但我不知道需要什么 .htaccess
配置才能让我的代码在服务器上工作,我已经尝试过这个,但它不起作用,因为服务器给出了 500 Internal server error
:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ https://www.johnny.group:8000/$1 [P]
index.js
import express from "express";
import cors from "cors";
const app = express();
app.use(cors());
const port = process.env.PORT || 8000;
app.use(express.json());
app.get("/", (req, res) => {
try{
res.send("Hello World!");
}
catch(err){
res.send(err.message);
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
注意那些可能导致错误的情况:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo systemctl restart apache2
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://localhost:8000/$1 [P,L]