@alysson_lynch
To run Node.js in a browser via a Linux Apache server, you'll need to set up a reverse proxy using Apache's mod_proxy
module. Follow these steps:
1 2 |
a2enmod proxy a2enmod proxy_http |
Add or modify a VirtualHost block to proxy requests to the Node.js server. Ensure that your VirtualHost block contains the following directives:
1 2 3 4 5 6 7 |
<VirtualHost *:80> ServerName your-domain.com ProxyPreserveHost On ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ </VirtualHost> |
Update your-domain.com
with your actual domain or IP address. The ProxyPass
and ProxyPassReverse
directives define the proxying to http://localhost:3000/
, where your Node.js server is running on port 3000. Adjust the port as per your Node.js server's configuration.
Save the configuration file and exit the text editor.
1
|
service apache2 restart |
With this setup, when you access your domain in a browser, Apache will forward requests to your Node.js server running on port 3000, and the Node.js application will respond as expected.
Note: Make sure that any firewall settings or security group configurations on your Linux server allow incoming connections on the specified ports.