簡體   English   中英

如何在 Centos8 上運行 NodeJS 和 Apache 以及 Apache 虛擬主機文件?

[英]How can I run NodeJS and Apache together with an Apache virtual host file on Centos8?

我的 NodeJS 應用程序在 example.com:3000 上運行。 顯然,告訴用戶輸入 :3000 是不合適的。 我希望它在 example.com 上運行,但我無法將 Node 設置為 :80,因為我的 Apache PHP 前端位於 :80。

我正在運行 CentOS 8。我在 /etc/httpd/conf.d 中創建了一個名為 proxy.conf 的文件,並在其中刪除了以下幾行。

<VirtualHost *:80>
        ErrorLog /var/log/httpd/error.log
        CustomLog /var/log/httpd/access.log combined
        ProxyRequests On
        ProxyPass / http://localhost:3000
        ProxyPassReverse / http://localhost:3000
</VirtualHost>

但是,它只會轉到我的常規非節點頁面。

問題是,apache 如何知道您何時需要 PHP 服務器,或者何時需要 Node 服務器。 您需要按ServerName拆分它們。

您需要一個ServerName屬性,以便apache知道將該VirtualHost發送到另一個進程。

<VirtualHost *:80>
    // PHP Server
    ServerName example.com www.example.com
</VirtualHost>
<VirtualHost *:80>
    // Node Server
    ServerName node.example.com
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
    ProxyRequests On
    ProxyPass / http://localhost:3000
    ProxyPassReverse / http://localhost:3000
</VirtualHost>

此外,您必須將node.example.com放在 DNS 中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM