Use Proxy to redirect my Site? - apache

I want to redirect my Apache Server to my node server running on other
port on localhost Like when i enter localhost:80 it should redirect my node server which is running on localhost:3000.

<VirtualHost *:3000>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:80/example/
ProxyPassReverse / http://localhost:80/example/
</VirtualHost>

Related

Ubuntu Apache Redirect All Request to HTTPS except Jenkins

I am creating a configuring a Server using Ubuntu and Apache. Everything works fine except that when I use redirection of HTTP to HTTPS.
How can I write an exception case where every http request is redirected to HTTPS except when its for JENKINS.
JENKINS : http://www.example.com:8080/ <= SHould not be redirected to HTTPS
Normal Request : http://www.example.com/ <= Should be redirected to HTTPS
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>
Your sample configuration looks almost correct. You can create a separate VirtualHost for port 8080.
<Virtualhost *:8080>
ServerName example.com
.
.
ProxyPass / http://jenkins:8080/
.
.
</Virtualhost>
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>

Apache reverse proxy match requests

My server hosts two web services: WordPress(on Port 8080) and Flask(on Port 8081). I am setting up a reverse proxy as I want any requests start with /admin goes to Flask and all others go to Wordpress.
For example:
http://aa.mcmaster.ca/admin/aa Goes to Port 8080
http://aa.mcmaster.ca/page1 Goes to Port 8081
http://aa.mcmaster.ca/page1 Goes to Port 8081
My setting is:
<VirtualHost *:80>
DocumentRoot /wordpress/wp-content
SSLProxyEngine On
ProxyPreserveHost On
ServerName aa.mcmaster.ca
ProxyRequests off
ProxyPass /admin http://aa.mcmaster.ca:8080/
ProxyPassReverse /admin http://aa.mcmaster.ca:8080/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /wordpress/wp-content
SSLProxyEngine On
ProxyPreserveHost On
ServerName aa.mcmaster.ca
ProxyRequests off
ProxyPass /http://aa.mcmaster.ca:8081/
ProxyPassReverse / http://aa.mcmaster.ca:8081/
</VirtualHost>
It doesn't work. I am stuck on how to set up to matchs requests other than /admin. Can I get some help?
Thanks!
Use below ProxyPass in a single VirtualHost and test.
ProxyPass /admin/ http://aa.mcmaster.ca:8080/
ProxyPassReverse /admin/ http://aa.mcmaster.ca:8080/
ProxyPass / http://aa.mcmaster.ca:8081/
ProxyPassReverse / http://aa.mcmaster.ca:8081/

Redirect a virtualhost http & https to another virtualhost server

I have 2 apache 2.4 serverA and serverB with several virtualhost. All incoming requests arrive on serverA.
How do I forward http and https request for a specific virtualhost name from serverA to serverB?
My wamp ServerA setup is:
into my hosts file
127.0.0.7 example.com
The virtualhost:
<VirtualHost *:*>
ServerName example.com
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
</VirtualHost>
My serverB ip is 192.168.1.105 and I setup a virtual host on it with the same name example.com
when I use http://example.com I stay on the wamp home page like http://localhost
and when I use https://example.com I have error 403 (Forbidden) on serverA
After a long night, I find a solution:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
ServerName example.com
</VirtualHost>
<VirtualHost *:443>
SSLProxyEngine on
SSLCertificateFile "${APACHE_DIR}/conf/ssl_example.com/server.crt"
SSLCertificateKeyFile "${APACHE_DIR}/conf/ssl_example.com/server.key"
ErrorLog "logs/example.com-ssl_error.log"
CustomLog "logs/example.com-ssl_access.log" common
ProxyPreserveHost On
ProxyPass "/" "https://192.168.1.105/"
ProxyPassReverse "/" "https://192.168.1.105/"
ServerName example.com
</VirtualHost>
in ServerA virtualhost add a simple:
Redirect / https://serverb.examample.com/

Virtual host with XAMP and APPSERVER

I have XAMPP and Appserver installed in one server (The first listens port 8080 and the second listens port 80).
I have a domain: example.com
I have this in APPSERV:
<VirtualHost 1.2.3.4:80>
ServerName example.com
DirectoryIndex index.php index.html
DocumentRoot "C:/appserv/www/folder"
</VirtualHost>
Is there a way so I can send that request to port 8080?
Here is a simplified version of how I accomplished it with ProxyPreserveHost
<VirtualHost www.example.com:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Redirect http to https by configuring .conf file of apache

I have configure apache to tomcat configuration by code like
<VirtualHost *:80>
ServerName captiveportal
ProxyPass / http://ip:port/path
ProxyPassReverse / http://ip:port/path
</VirtualHost>
Now i want to reirect this request to https
How can i achieve this ?
After looking your answer i have changes my configuration like
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/httpd/conf/crt1.crt"
SSLCertificateKeyFile "/etc/httpd/conf/key1.key"
ProxyPass / http://ip:port/path
</VirtualHost>
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://ip:port/path
</VirtualHost>
but when i type captiveportal on my browser it redirects me on url https://ip:port/path and it displays problem loading page
One more thing i don't want to display https://ip:port/path on browser.
Note :- https://ip:port/path where port is my tomcat port and ip is machine ip where tomcat run.
You could do something like this:
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://my.host.name/
</VirtualHost>
...and then put your ProxyPass directives in side your SSL VirtualHost block instead.