简体   繁体   中英

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

What I am trying to do

After running the command (export PORT=3000 && node server.js) my node.js app ( StackEdit ) is served at: http://example.com:3000/ .

The command (export PORT=80 && node server.js) wouldn't work considering that Apache already uses port 80 on the server.

As I am new to Node.js, an easy way to make the node.js app available at http://example.com/ (ie port 80) would be to set up Apache as a reverse proxy.

Here's what I've tried

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

Trial (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>

This simply shows the directory listing for the public directory. So, in this case the requests aren't reaching the node.js app.

Trial (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>

This doesn't work either. It takes me to some default apache page.

What I am missing here?

Change your Location directive as

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

basically, Location directive is a prefix of the path component of the URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM