I'm trying to run a small app I've wrote in nodejs on our server with forever. When I start my app like this:
forever app.js
In my folder /home/me/apps/myapp/
and the app is listening on port 61000
What should be the content of my .htaccess file under mydomain.me/myapp/
?
Current .htaccess
content (not working):
RewriteEngine On
# Redirect a whole subdirectory:
RewriteRule ^myapp/(.*) http://localhost:61000/$1 [P]
You should use Apache mod_proxy not mod_rewrite to run a Node.js app in Apache:
<VirtualHost :80>
ServerName example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /myapp>
ProxyPass http://localhost:61000/
ProxyPassReverse http://localhost:61000/
</Location>
</VirtualHost>
If you can't add a virtual host for your Node app you can try with htaccess and something like this:
RewriteEngine On
RewriteRule ^/myapp$ http://127.0.0.1:61000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/myapp/(.*)$ http://127.0.0.1:61000/$1 [P,L]
I will answer my own question, even though I think Michelems answer is also right.
My initial .htaccess file works.
RewriteEngine On
RewriteRule ^myapp/(.*) http://localhost:61000/$1 [P]
The thing I did wrong was creating actually the folder mydomain.de/myapp/
and put the .htaccess there. I have now the rewirte settings in my DocumentRoot/.htaccess, no public folder called myapp
and it works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With