Redirect Apache Subdomain:80 to 8096 - linux

I have a domain..
sub.example.com, which you can reach via port 80.
Everytime a user is searching for that Domain, I want to get an redirect to port 8096, but the user should not realize that.
Does anyone have a suggestion for this how to configure a vHost?

You can use redirect to port 80 to 8096 or use Proxy configuration.
For me the better is the Proxy because the client not view your port 8096 in his web browser
Example to Proxy configuration :
Firts make sure apache listen on port 8096 :
netstat -laputen|grep 8096
If you have no reply, check Listen port in /etc/apache2/ports.conf :
Listen 8096
Restart apache and recheck LISTEN in netstat
service apache2 restart
netstat -laputen|grep 8096
If is not apache who listen the port 8096, you just need to create vhost to listen on port 80, not 8096
Enable proxy module in apache2 :
a2enmod proxy proxy_http
Restart apache :
service apache2 restart
Create Virtual Host :
/etc/apache2/sites-available/sub2_example_com.conf
<VirtualHost *:80>
# Just listen to sub2.example.com, the others sub-domain going to the default Vhost
ServerName sub2.example.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8096/
ProxyPassReverse / http://127.0.0.1:8096/
</VirtualHost>
# Just if is not another app who listening to port 8096
<VirtualHost *:8096>
ServerName sub2.example.com
ServerAdmin webmaster#example.com
DocumentRoot /var/www/my_website
ErrorLog ${APACHE_LOG_DIR}/my_website_error.log
CustomLog ${APACHE_LOG_DIR}/my_website_access.log combined
</VirtualHost>
Enable Virtual Host :
a2ensite sub2_example_com.conf
Reload Apache :
service apache2 reload
Open your web browser in sub2.example.com , apache redirect all request in port 8096
Doc apache :
https://httpd.apache.org/docs/current/mod/mod_proxy.html

Related

Apache and Node on port 80

**I have seen a similiar question here, with no proper answer
I want both Apache and Node.js to run on port 80, so that it won't be necessary to type port number at the address bar.
But my Node.js app won't work when I listen on port 80 instead of 3000, I guess that's because Apache is already on 80.
Or, the solution requires to actually use other port than 80 and somehow hide it?
In TCP, you can only run 1 service per port. As soon the port is assigned to a service, it becomes unavailable to anybody else.
However there is a way to share port betwen NODE and APACHE, proxying the connections using an Apache 2 Module (mod_proxy and mod_proxy_http). You can get more details here:
how to put nodejs and apache in the same port 80
Apache configuration example to use Apache in requests to http://example.com/
and Node.js for requests to http://example.com/node/:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example/
<Location /node>
ProxyPass http://127.0.0.1:8124/
ProxyPassReverse http://127.0.0.1:8124/
</Location>
</VirtualHost>

How do I redirect all calls on one port to the same URL on another port with apache?

I'm hosting a sails.js application on the default port 1337. I have an apache serving as its proxy on port 8080:
[root#ip-192-168-0-XX conf.d]# cat nodetest.conf
Listen 8080
<VirtualHost 192.168.0.XX:8080>
Options -Indexes
ProxyRequests on
ProxyPass / http://localhost:1337/
</VirtualHost>
The Sails application has an API. So for instance, if I want to post a message, I enter this into my browser:
http://localhost:1337/Message/postMessage
I want that to happen when I enter the same address on port 8080.
http://localhost:8080/Message/postMessage
I am brand new to this Apache stuff, so I don't even know what the thing I want to do right now is called? Reverse Proxy? Regular Proxy? Redirects? I just don't know.
Firstly, I guess you would really only need to do this if you have Apache hosting other sites on the same server.
If you have no intention of running other sites on the same server with Apache, you can always just hit the Sails server directly at port 80 or 8080 by changing the port in your sails application in the config/local.js file.
Change
// port: process.env.PORT || 1337,
To
port: process.env.PORT || 80,
For other applications, like load balancing or basic proxying, I think nginx would be a far better solution.
The standard configuration for using Apache as a proxy for Sails would be something like this:
<VirtualHost *:8080>
ServerName example.com
ServerAlias www.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:1337/
ProxyPassReverse http://localhost:1337/
</Location>
</VirtualHost>

Apache reverse proxy configuration issue

i have a problem with setting up an apache reverse proxy server and hope you can help.
I have 3 ubuntu web servers, available on https://service1.domain.com, https://service2.domain.com:4433 and so on...
Now, i will access these servers without typing the port in the addressbar.
So my idea is to use an reverse proxy server, that i can type in service2.domain.com and it redirects to service2 (https).
I installed an ubuntu server with apache and enabled the modules:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
Then i set up the 000-default.conf on the proxy with the following content:
<VirtualHost service1.domain.com:80>
ProxyPreserveHost On
ProxyPass / https://service1.domain.com/
ProxyPassReverse / https://service1.domain.com/
</VirtualHost>
<VirtualHost service2.domain.com:80>
ProxyPreserveHost On
ProxyPass / https://service2.domain.com/
ProxyPassReverse / https://service2.domain.com/
</VirtualHost>
The ports 80 and 443 on the router are forwarded to the proxy server.
On the service(1-3) servers, SSL is enabled with certificates from Lets Encrypt.
Now, if i try to open site service1.domain.com, i get an error (cert_name).
The sites now should not be accessible directly, because there is no port forwarding anymore.
My question is now, how is the right config for reverse proxies? Do i need to enable a certificate for each service also on the proxy server?
Thank you for your help!
Not exactly sure what your end goal is. The certificate is for the client facing server. If you want people to hit the site without having to set the port, you can use the Redirect statement in the virtual host config.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com
</VirtualHost>
Which would forward any non ssl traffic to use the ssl virtual host.

how to run multiple cross platform web application on the same server using different ports?

I am running a java web application on tomcat 7.0, which is setup on media temple Ubuntu 16.04 server. The application is running on port 8080, and I have a domain which is binded to the port.
e.g. public-ip-of-server:8080 xyz.com
Now, I want to run a node js application (rocket-chat) on the same Linux server using port 3000. I have configured the whole application, and the application is running on localhost:3000/ but when I am trying to access the application using public IP of the server (e.g. public-ip:3000/), I am not able to access it.
I have allowed the traffic on port 3000 using command,
ufw allow 3000
I also edited apache2.conf,
ProxyPass /rocketchat http://public-ip-of-server:3000/
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module
modules/mod_proxy_http.so
but after changing this parameter I am not able to restart the apache2 service.
so I revert back the changes.
what should I do to run both the application (java and node js) on the same Linux server ? can anyone please help me out.
Just bind nodejs app to interface 0.0.0.0 instead of 127.0.0.1.
In your Apache configuration, you should use the localhost instead of public ip. So instead of:
ProxyPass /rocketchat http://public-ip-of-server:3000/
use:
ProxyPass /rocketchat http://localhost:3000/
I am using Ubuntu server so httpd.conf is not present there, so I have created another file, in sites-available folder of apache2.(e.g xyz.conf).
I have two domain which pointing to the same media temple name server,
I used one domain for pointing tomcat application on port 8080 and another domain for node js application on port 3000, by making virtual host in xyz.conf
<VirtualHost *:80>
ServerName xyz.com
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
<VirtualHost *:80>
ServerName abc.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
After this I enabled proxy mode using command :
sudo a2enmod proxy
And also make this xyz.conf file as site configuration file, using command,
sudo a2ensite xyz.conf
It will ask you to reload the apache2 service,
just reload it and restart,
e.g sudo systemctl restart apache2.service
The problem resolved by forwarding the request, which is received on port 80 of apache2, to tomcat:8080 and nodejs:3000, by creating virtual host.

Exposing a webserver not listening on port 80

My question is probably trivial and a duplicate, but either I cannot formulate it or it's not been answered on SO yet.
I have two webservers on a Digital Ocean droplet. One is listening on port 80 and can be accessed via example.com (DNS are on route 53), and the other is on port 8080: how can I make it accessible from example-2.com?
I suppose the software I'm looking for would intercept the HTTP requests, check the referrer, and route those coming from example.com to port 80 and those coming from example-2.com to port 8080. What is it?
This can not be done using only DNS. By default web browsers attempt to connect to port 80 when the url starts with "http" without specifying a port. The user would have to know to connect to port 8080 and explicitly access the URL as
http://example-2.com:8080
I am assuming you are running both web server instances on the same OS environment/IP address, though this would also work for separate hosting environments. What you probably want is a reverse web proxy which can inspect the requested domain name and route to an appropriate server instance. You would run the reverse web proxy on port 80, and probably move the server you are currently running on port 80 to another port (say, 8081).
Apache with mod_proxy and the virtual hosting settings is a possible solution. Assuming example.com and example-2.com point to the Apache instance configure it something like this:
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#example.com
ProxyRequests off
ProxyPreserveHost on
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>
<VirtualHost *:80>
ServerName example-2.com
ServerAdmin webmaster#example-2.com
ProxyRequests off
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>

Resources