簡體   English   中英

Apache反向代理設置(針對node.js應用程序)不起作用?

[英]Apache reverse proxy setup (for node.js application) not working?

我要做什么

運行命令(export PORT=3000 && node server.js) 網址訪問我的node.js應用程序( StackEdit ): http://example.com:3000/ : http://example.com:3000/ : (export PORT=3000 && node server.js)

考慮到Apache已在服務器上使用端口80,該命令(export PORT=80 && node server.js)將無法工作。

由於我是Node.js的新手,因此可在http://example.com/ (即端口80)上使用node.js應用程序的簡單方法是將Apache設置為反向代理。

這是我嘗試過的

/etc/apache2/sites-available/example.com.conf

試用(1):

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com/public
    ErrorLog /var/www/example.com/logs/error.log
    CustomLog /var/www/editor.aahanblog.com/logs/access.log combined

    ProxyPass / http://example.com:3000/
    ProxyPassReverse / http://example.com:3000/
</VirtualHost>

這只是顯示了public目錄的目錄列表。 因此,在這種情況下,請求沒有到達node.js應用程序。

試用(2):

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example.com/public
    ErrorLog /var/www/example.com/logs/error.log
    CustomLog /var/www/example.com/logs/access.log combined

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    <Location /var/www/example.com/public>
        ProxyPass http://mydomain:3000/
        ProxyPassReverse http://mydomain:3000/
    </Location>
</VirtualHost>

這也不起作用。 它帶我到一些默認的Apache頁面。

我在這里想念的是什么?

將您的位置指令更改為

<Location /> from <Location /var/www/example.com/public>

基本上,位置指令是URL路徑部分的前綴

暫無
暫無

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

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