APACHE REDIRECT TO TOMCAT USING MOD_PROXY - mod-proxy

I am trying to implement a redirect for apache2 t tomcat.I would like to have a url like this: share.com to open to alfresco login page, but currently I have to use the url like this:
share.com/share/ .
I have done research and what I achieved was removing the 8080 port from the url:
share.com:8080/share/
only remains the /share; How can I remove the /share part too?

I believe what you are trying to do can be achieved with a ProxyPass. The below entry will cause everything to go to Tomcat/share.
ProxyPass / http://localhost:8080/share
ProxyPassReverse / http://localhost:8080/share
For the above to work, mod_proxy_http will need to be installed and loaded. This would either be done with a dynamic load config line in the conf file:
LoadModule proxy_http_module modules/mod_proxy_http.so
Or compiled into Apache:
./httpd -l | grep proxy
mod_proxy.c
mod_proxy_connect.c
mod_proxy_ftp.c
mod_proxy_http.c
mod_proxy_scgi.c
mod_proxy_ajp.c
mod_proxy_balancer.c

Related

How can I make a ProxyPass work for all pages without defining a new rule for each page

I'm very new to setting up apache configs. The docs don't make much sense to me, I have a node app running on a port that functions as a website, but I want to be able to connect to it with my domain. I've been looking around and figured I need to use a ProxyPass to redirect traffic from port 443 (https) to the port the app is running on (I already use apache for other stuff so I didn't want to switch). And it works generally, but is there a way to make only a single ProxyPass rule that will handle all pages (e.g. I go to https://example.com/ it will use https://localhost:4450/ and if I go to https://example.com/example it will use https://localhost:4450/example and for all other pages).
I would think I need a RewriteRule, but I don't really understand how I can get the page (whatever is after the first / or none) using it.
You simply run apache as a reverse proxy here is an example configuration:
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/file.pem
ProxyPreserveHost On
ServerName localhost
ProxyPass / http://0.0.0.0:4450/
ProxyPassReverse / http://0.0.0.0:4450/
</VirtualHost>
and you have to enable the proxy modules like that
a2enmod proxy
a2enmod proxy_http

VirtualHost not redirecting

I am trying to redirect http://eamondev.com:3000 to https://omniatm.eamondev.com with a VirtualHost. I am using node to serve a site to http://eamondev.com:3000. I am using vhost with node like this:
app.use(vhost('omniatm.eamondev.com', express.static('/')));
I have never used vhost and it took me a while to figure this out without having to split up all my code like I was working with more than one site (when I am not), so I'm not sure if it is exactly how it should be for an Apache redirect to work.
In my apache conf file I have:
<VirtualHost *:80>
ServerName omniatm.eamondev.com
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
</VirtualHost>
I am also using WHM on a VPS, I'm not sure if this is relevant or not, but the ServerName (with protocol, what I type into the browser) needs to be https://omniatm.eamondev.com.
I cannot serve node on port 80 of my server (and then redirect to subdomain) because my main site (http://eamondev.com) is running on port 80.
I have referenced most of the stackoverflow questions about this and nothing has worked. I should mention (although I'm not sure exactly how it is relevant, I just saw it in a stackoverflow question I looked at), my hosting support (bluehost) used WHM to set things up with a wildcard ssl certificate to make the omniatm.eamondev.com subdomain https.
How do I redirect http://eamondev.com:3000 to https://omniatm.eamondev.com using apache (or vhost)?
Proxy passing as given in the question will not do any redirects instead it will retain the URL as such and proxy the content from elsewhere. In Apache configuration, we have an option to do redirects, in the bellow sample, we are checking for the host and based on it issuing an redirect to the desired URL
<VirtualHost *:80>
ServerName omniatm.eamondev.com
Redirect / https://omniatm.eamondev.com
<If "%{HTTP_HOST} != 'eamondev.com:3000'">
Redirect "^/?(.*)" "https://omniatm.eamondev.com/$1"
</If>
</VirtualHost>

Apache on CentOS issue configuring routing to "Index.html" (uppercase"I")

I have a project being deployed such that an Apache instance is running on CentOS (DMZ) which is due to forward all requests to a TOMCAT instance running behind the firewall. For instance, a request:
www.Example.com
needs to be forwarded to:
HTTP://<servername behind the firewall>:<port number>/Blabla/Index.html
(Note that Index.html has a capital I).
I should note that the whole project required extensive review as it was developed under Windows (case insensitive filenames) but the running environment is Linux, and now all filenames and their references are fully synchronized.
The problem appears to be that it is not possible to configure within Apache to forward requests to Index.html and it converts it to index.html, which does not exist.
I can change all the file names to lowercase, but this will take quite some effort.
Is there any way to force Apache to use as-is what I define (i.e. if lowercase, use lowercase; if uppercase, use uppercase; if mixed, use mixed).
Thanks in advance.
You should be able to use mod_speling from Apache. In your configuration file, simply put:
CheckSpelling On
CheckCaseOnly On
And reload Apache using either:
/etc/init.d/httpd reload
Or if you're using CentOS 7:
systemctl reload httpd
This should now make all the files in your website directory insensitive.
If you're using virtualhosts, you may add this option into it:
DirectoryIndex Index.html
So your virtualhost should be like that :
<VirtualHost *:80>
ServerName website_name
DocumentRoot website_directory
DirectoryIndex Index.html
</VirtualHost>
You can paste it in /etc/httpd/conf.d/mywebsite.conf and reload apache with :
systemctl reload httpd
If you have CentOS/7. For older versions of CentOS use this command:
service httpd reload

How to Setup Website Directory (Custom Host) on Centos 7

I'm trying to figure out how to have the website function after i point the DNS to the server.
by default, (after fresh install of apache, mysql, php) the main server directory is situated at var/www/html so if i upload test html file, via default server ip the html file will show.
i'm trying to setup a custom folder i.e var/www/examplewebsite.com/public_html and then the public_html would function as the go-to folder for when user goes to my website. Multiple websites on one IP (server) would be great too
i found some information from http://bit.ly/1kguprn but i do not see the NameVirtualHost and the paragraph under that.
I'm a newbie to the Centos/Linux environment, any help would be greatly appreciated :)
You have a nice tutorial here: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-6
Basically, create a folder and an index for testing purposes:
sudo vi /var/www/example.com/public_html/index.html
add the Virtual directive in your apache config file (:
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot /var/www/example.com/public_html
ServerName www.example.com
ServerAlias example.com
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/requests.log
</VirtualHost>
Restart apache:
sudo service httpd restart
Check this documentation for Centos 7. They have a nice initial tutorial.
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-2-files-and-processes
First, I will recommend to you that check if you have the httpd service installed and active.
sudo service httpd status
if non active
sudo service httpd start
once active
Check the if the ports 80 and 443 (https are active)
sudo netstat -tulnap | grep :80
sudo netstat -tulnap | grep :443
if they are active, test the server. http://yourserverip or https://yourserverip
By default it should go to the apache webserver page.
Once you can see the page. Try to create the initial index.html page in
/var/www/html
vi /var/www.html/index.html
click i for insert
copy the following html
Test
Test web page
In the tutorial, they will explain the rest of the configuration.
#Moderator The tutorial provide a good long material for the reader, I got punish for answer correctly by the moderator. I think the website are long enough to clarify the question and I think copy again the tutorial here is not proper answer.
Also check the next documentation for changes between Apache 2.2 and 2.4
https://linode.com/docs/security/upgrading/updating-virtual-host-settings-from-apache-2-2-to-apache-2-4/
If you have any problems, comment here.

.htaccess rewrite mode is not working

rewrite script in .htaccess
RewriteEngine on
RewriteRule ^index/page/(.*)$ index.php?page=$1
It works in local machine. but in server it does not work. can any body help me?
Have you verified that the rewrite module is loaded on your server? If the server is running apache you should be able to verify this with
apache2ctl -t -D DUMP_MODULES
and looking for the rewrite_module in the response. (NB: You may need apachectl depending on the machine you are using.)
If it is not loaded you might need to change your server configuration. This is doable (again, depending on the version of apache in use) with a step like
a2enmod rewrite
or ensuring your httpd.conf file contains
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
or by ensuring there's a symbolic link between the rewrite.load file /etc/apache2/mods-enabled and /etc/apache2/mods-available.
Don't forget to restart apache afterwards.

Resources