Apache2 redirect Alias to port - linux

i know this can be done with mod_rewrite or mod_proxy, if i'm correct..
but the problem is that i've tried so many times without success.
My problem is that i have a server mapped on 192.168.1.110, with two open ports (80 apache2 and 8080 tomcat)
I want to install something like shellinabox that runs on port 4200, and redirect it to a apache2 alias like : http://mywebsite.com/shellinabox
without having to open port 4200 on my router.
How to do that?
Any working solution?
Thanks

Related

Running Node.Js and Apache on the same server and different domain

I have a web server which contains the files for both domains
1-exemple.id and 2-exemple.info.
I want to run Wordpress on "1" and NodeJs for "2".
1" points to the directory /home/xxxxx/public_html and 2" points to the directory /home/xxxxx/public_html/xxxxx.info.
The issue here is that I have tried a couple of times to get this working. I used iptables for forwarding traffic from port 3000(NodeJs) to 80. This made it worse as the NodeJs server is now showing on both domains 1" and 2".
Looking forward to hear your suggestions.
Please note: I am using CentOs7
If you want to forward traffic to a different port you need to configure Apache as a proxy in your virtual hosts file:
ProxyPass "/" "http://127.0.0.1:3000"
ProxyPassReverse "/" "http://127.0.0.1:3000"
Make sure you activate the proxy modules for Apache:
sudo a2enmod proxy
sudo a2enmod proxy_http

How to run express app on port 80 without sudo access

I am using the express framework for nodejs on a Dreamhost VPS and I want to run my server on port 80 but all of the answers I've seen require sudo/root access but on a Dreamhost VPS I am not given this permission. I can't edit any of the Apache files. The only thing I am able to do is create a .htaccess file. How can I achieve this?
You can try to run Node on a different port (greater than 1024, since those of 1023 or lower require root) and just proxy the requests through Apache by adding something like this to your .htaccess file:
RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:8080/$1 [P,L]
(In this example Node would be running on port 8080).
For anyone who comes across this and has Dreamhost, the solution I came up with was creating a proxy. In the Dreamhost panel there is an option to create a proxy for a domain that you can then direct to go to any port for that domain and I simply made the proxy go to port 3000 and then my node server ran on port 3000.
#Frxstrem's answer also works but it failed to work when I shared a link and is kind of a hacky solution.

Where do I put my Node JS app so it is accessible via the main website?

I've recently installed a nodejs app (keystone) app in my home/myusername/myappname directory.
When I visit www.mydomain.com, nothing displays - even after turning on my nodejs app.
Where should these files be?
I am running ubuntu 16.04.
In the past I have worked with a var/www folder, but I am not using apache - do I need to manually create this folder?
Thanks!
For your app to be visible it has to be running (obviously) and accessible on port 80 (if you want it to be available without adding a port number to the URL).
It doesn't matter where it is on the disk as long as it's running.
You don't need Apache or nginx or any other server. Your Node app may listen on port 80. But alternatively it can listen on some other port and your other server (Apache, nginx, etc.) can proxy the requests to that port.
But if your app is listening on, e.g. port 3000 then you should be able to access it as http://www.example.com:3000/.
Also, make sure that your domain is configured correctly. It's A record for IPv4 (or AAAA for IPv6) of the www subdomain should be equal to the publicly accessible IP address of your server.
And make sure that the port you use is not blocked by the firewall.
Update
To see how you can set the port with Keystone, see:
http://keystonejs.com/docs/configuration/#options-server
It can be either changed in the config or you can run your app with:
PORT=80 node yourApp.js
instead of:
node yourApp.js
but keep in mind that to use the port number below 1024 you will usually need the program to run as root (or add a special privilege which is more complicated).
It will also mean that this will be the only application that you can run on this server, even if you have more domain names.
If you don't want to run as root or you want to host more application, it is easiest to install nginx and proxy the requests. Such a configuration is called a "reverse proxy" - it's good to search for info and tutorials using that phrase.
The simplest nginx config would be something like this:
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://localhost:3000;
}
}
You can set it in:
/etc/nginx/sites-available/default
or in a different file as e.g.:
/etc/nginx/sites-available/example
and then symlinked as /etc/nginx/sites-enabled/example
You need to restart nginx after changing the config.
You can find more options on configuring reverse proxies here:
https://www.nginx.com/resources/admin-guide/reverse-proxy/
You need to make a proxy between Apache and your Node.js application because Node.js has a built-in server. Supose your Node.js app is served on 9000 port. Then you need to make a proxy to redirect all trafic in 80 port to 9000 port where the Node.js app is running.
1. Enable mod_proxy
You can do this through a2enmond.
sudo a2enmod proxy
sudo a2enmod proxy_http
2. Set the proxy
Edit the /etc/apache2/sites-available/example.com.conf file and add the following lines:
ProxyRequests Off
Order deny, allow from All
ProxyPass / http://0.0.0.0:9000 ProxyPassReverse / http://0.0.0.0:9000
This basically say: "Redirect all traffic from root / to http://0.0.0.0:9000. The host 0.0.0.0:9000 is where your app is running.
Finally restart apache to enable changes.

Running nodejs app on Centos7 apache server

I'm trying to run a node web app (built with meteor) on a Centos7 server running EasyApache4 with WHM cPanel. I'm trying to run it on a subdomain off of one of our main websites on port 8080.
When going to the subdomain on port 8080, the connection just times out, but can see the html when using curl to access it.
Does anyone have any ideas why it won't work through the browser, and also how I can get it to look like it's running straight from the subdomain instead of having to go directly to the port.
EDIT
Below is the curl we are using to view the html
curl http://subdomain.site.com:8080
Doing that brings back the html no problems
Had the same problem today. I am using Memset Centos7 server with WHM/CPanel, running EasyApache 4.
After trying everything I could think of, I realised that I had a basic firewall setup, which closed all ports that were not listed. After adding port 8080, it worked.
Used this:
sudo iptables -I INPUT 1 -i + -p tcp --dport 8080 -j ACCEPT
I am not 100% certain how secure this is, as I am still researching.

How can I find where node.js is running?

I have a VPS with node.js installed, I already uploaded a basic example to test it on the server, so I tried doing this:
I access by SSH, navigate to my project folder and run
node app.js
I get this message
Express server listening on port 8080
I thought i could see my app here
example.com:8080 or server.example:8080... but nothing. Then I tried with the info from os.networkInterfaces(); and os.host(); and still nothing happen
could you help me out? as you can see I am a total noob on node.js. What I'm doing wrong? or what should I do before running my app? Something related to DNS's? i have no idea
How do you ssh to your host? with ip or name? Is it something like:
ssh root#example.com
if so then at least you know your DNS is ok.
Once on the server do a
netstat -a
if you find *:8080 then your server is listening in the default ip. If you see something like 12.23.45.67:8080 then this number is the ip your server is listening.
ifconfig
will give you the servers ip. This should be the same as the ip of example.com. If not then maybe there is some router/firewall in front of your server and you have to configure that to allow port 8080 to reach your server.
if someone ever has the same problem this is how i solved on CentOS:
Open this file
/ Etc / csf / csf.conf
Add the required port
Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,26"
Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,37,43,53,80,110,113,443,587,873"
Restart
# # Csf-r

Resources