i am trying to configure my apache server as proxy to serve two internal services , one listening on 8080 and should receive traffic on specific URL and the other listening on 8077 and should receive all other http traffic
I deployed and configured apache on the same server where these two services running and it is listening to 443 along with all SSL configuration and it is working fine
also I enabled the proxy_module, proxy_http_module and proxy_http2_module
What I want to achieve
if the requested URL is /webhook1 --> pass it to EP1 http://localhost:8080 and
any other requested URL should be passed to EP2 http://localhost:8077
My Current Configuration towards the first service
ProxyPass /webhook1 http://localhost:8080
ProxyPassReverse /webhook1 http://localhost:8080
Now I want to define another proxy pass to be something like
ProxyPass / http://localhost:8077
ProxyPassReverse / http://localhost:8077
putting both configuration together is not working , appreciate your help in how to configure apache to achieve my requirement
Thank you in advance
Put the ProxyPass rules in the correct order as required
if you want to evaluate /webhook1 rule and send it to 8080, else send the traffic to 8077 the rules should be on the following order
ProxyPass /webhook1 http://localhost:8080
ProxyPassReverse /webhook1 http://localhost:8080
ProxyPass / http://localhost:8077
ProxyPassReverse / http://localhost:8077
You may write ssl.conf file under /etc/apache2/sites-enabled/ as follows:-
RewriteEngine on
ProxyPass /webhook1 http://127.0.0.1:8080/
ProxyPassReverse /webhook1 http://127.0.0.1:8080/
RewriteRule ^/$ /webhook1/ [R,L]
RewriteEngine on
ProxyPass / http://127.0.0.1:8087/
ProxyPassReverse / http://127.0.0.1:8087/
RewriteRule ^/$ /EP2/ [R,L]
It will automatically redirects to HTTPS if ssl certificate is configured in apache2.
Related
I'm running into a very serious problem.
Hope someone kind can help.
Please see the code below first.
This is part of my Apache configuration.
First, the URL of the target web server is http://localhost:30001 ~ 30010. Identifies the site to be accessed through each PORT.
When I receive input as "http://localhost/wksp/30001", I use RewriteEngine to make it "http://localhost:30001". This part works without any problems.
However, I tried to apply TLS and run "https" through ProxyPass and ProxyPassReverse again, but it is very difficult.
From what I understand, ProxyPassReverse accesses "http://localhost:[PORT]/" at first, but then communicates with Proxy through "https://localhost/".
Therefore, when communicating with the https protocol, the PORT cannot be dynamically acquired. For example, if http://localhost:30001 is the target, you need to communicate with the proxy server through port 30001.
In my code now, when HTTPS=on, PORT is written as 30001, but what I want is to keep holding the variable $1 when HTTPS=off.
If you have another approach, that's fine. lots of advice Thank.
<VirtualHost *:443>
...
SSLEngine On
ProxyPreserveHost On
SSLProxyEngine On
ProxyRequests Off
RequestHeader set Front-End-Https "On"
...
RewriteEngine On
RewriteRule ^/wksp/(.*) http://localhost:$1 [P]
ProxyPassReverse / http://localhost:$1
<Location />
Order allow,deny
Allow from all
RewriteEngine On
RewriteCond "%{HTTPS}" =off
RewriteRule ^:(.*) http://localhost:$1/ [P]
ProxyPassReverse http://localhost:$1/
RewriteCond "%{HTTPS}" =on
ProxyPass http://localhost:30001/
ProxyPassReverse http://localhost:30001/
</Location>
</VirtualHost>
If HTTPS=on, if you change the url port of ProxyPass and ProxyPassReverse to $1, the following error is displayed.
httpd[1584880]: AH00526: Syntax error on line 55 of /etc/httpd/conf.d/wksp-tls.conf:
ProxyPass Unable to parse URL: http://localhost:$1/
So basically, i have a apache2 server with https where i run some application
I am tring to using mod_proxy to proxy all traffic to url example.com/qb to [::1]:qb-webui-port.
So in /etc/apache2/mods-enabled/proxy.conf, i wrote:
ProxyRequests Off
<proxy *>
AddDefaultCharset off
Order Allow,Deny
Allow from all
</proxy>
ProxyPass /transmission http://[::1]:9091/transmission
ProxyPassReverse /transmission http://[::1]:9091/transmission
ProxyVia On
ProxyPass /qb http://[::1]:8112
ProxyPassReverse /qb http://[::1]:8112
The above is my similiar configuration for Transmission, i intended to do the same trick to Qbittorrent.
But it only returned plain html from example.com/qb.
In the firefox console i noticed that there were some request towards example.com/css, example.com/script etc.
This make me confused.
Can anyone provide some insights on this one?
Thx.
You missed the trailing slash on your addresses.
Here's my config file. I added a RewriteRule in case I enter the URL without the trailing slash. With these configs I haven't needed to modify anything else to get qb reverse proxy working.
I use the "/torrent/ subdir to access my qbittorrent webUI and it's listening on the 8080 port, so you should modify this in order to get your installation fully functional.
# Para qbittorrent
RewriteEngine on
RewriteRule ^/torrent$ "/torrent/$1" [R]
ProxyPass /torrent/ http://127.0.0.1:8080/
ProxyPassReverse /torrent/ http://127.0.0.1:8080/
I want to configure a server to listen to localhost adress with proxy pass.
Fist, I added a proxy pass configuration like that:
ProxyPass /test http://localhost:5959/ nocanon
ProxyPassReverse /test http://localhost:5959/
ProxyPassReverse /test http://domain_name.net/
The index is working fine, but the problem is when i click on some button to be redirected to another page. I expected the redirection would be like : http://domaine_name.net/test/anotherpage.php but it didn't work.
I tried another configuration but it didn't work
ProxyPass /test/ http://localhost:5959/test/
ProxyPassReverse /test/ http://localhost:5959/test/
ProxyPassReverse /test/ http://domain_name.net/test/
How can I resolve this issue ?
Do not put 2 ProxyPassReverse directives. Only one. And it should match the ProxyPass destination. So your first ProxyPassReverse only is required.
ProxyPass /test http://localhost:5959/ nocanon
ProxyPassReverse /test http://localhost:5959/
From the documentation for ProxyPassReverse, (https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassreverse):
This directive lets Apache httpd adjust the URL in the Location,
Content-Location and URI headers on HTTP redirect responses. [...]
You said in your question:
I expected the redirection would be like :
http://domaine_name.net/test/anotherpage.php but it didn't work.
this is normal. A proxy hides the final destination server to the client. If you want to redirect the client, do not use a proxy. Use mod_rewrite (RewriteRule and others).
I have installed apache httpd 2.2.15 in my app server. I need to get the login page(https://ip_address:9002/xxstorefront/xx/en/USD/login) when I hit on https://dev.xxyy.com/login. I have installed SSL certificate for my domain and set below redirect rules.
ProxyPass /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPassReverse /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPass /login https://localhost:9002/xxstorefront/xx/en/USD/login
ProxyPassReverse /login https://localhost:9002/xxstorefront/xx/en/USD/login
RewriteEngine On
RewriteRule ^(.*)/login http://%{ip_address:9001}$1/{xxstorefront/xx/en/USD/login}$2 [L,R]
When I hit on https://dev.xxyy.com/login, I get below error,
Not Found
The requested URL /login was not found on this server.
Apache/2.2.15 (CentOS) Server at dev.xxyy.com Port 443
When I hit on https://dev.xxyy.com, I get the apache default homepage.
Pls guide me how should I set the redirect rules.
Your configuration is invalid. Those two lines:
ProxyPass /login https://localhost:9002/xxstorefront/xx/en/USD/login
ProxyPassReverse /login https://localhost:9002/xxstorefront/xx/en/USD/login
overwrite those two:
ProxyPass /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPassReverse /login http://localhost:9001/xxstorefront/xx/en/USD/login
Rewite mechanism probably does not work at all:
RewriteEngine On
RewriteRule ^(.*)/login http://%{ip_address:9001}$1/{xxstorefront/xx/en/USD/login}$2 [L,R]
I think this configuration should solve your problem:
<VirtualHost *:80>
ServerName dev.xxyy.com
ProxyPreserveHost On
ProxyPass / http://localhost:9001/xxstorefront/xx/en/USD/
ProxyPassReverse / http://localhost:9001/xxstorefront/xx/en/USD/
</VirtualHost>
<VirtualHost *:443>
ServerName dev.xxyy.com
SSLEngine on
// other SSL directives
ProxyPreserveHost On
ProxyPass / https://localhost:9002/xxstorefront/xx/en/USD/
ProxyPassReverse / https://localhost:9002/xxstorefront/xx/en/USD/
</VirtualHost>
It defines two virtual hosts which work as proxies and map all requests to xxstorefront/xx/en/USD/...:
http://dev.xxyy.com/(.*) → http://localhost:9001/xxstorefront/xx/en/USD/(.*)
https://dev.xxyy.com/(.*) → https://localhost:9002/xxstorefront/xx/en/USD/(.*)
I am struggling with proxy reversing an SSL server in Apache.
Right now I have many websites under many subdomains in one domain.
For example:
gitlab.mydomain.com
nextcloud.mydomain.com
plex.mydomain.com
All the websites use Letsencrypt certificates so they are HTTPS enabled.
The thing is, that so far no server running at my localhost was HTTPS. For example Plex is running as a standalone HTTP server on my localhost which I simply proxy reverse using Apache and in the internet it is secured with Letsencrypt.
Now I need to proxy reverse an already secured HTTP server. Namely Jenkins - it is running with Letsencrypt on my localhost for various reasons. I should also mention that the certificate used to encrypt it on localhost is the same as the certificate I use in Apache.
So my Jenkins is running on port 8443 and my Apache configuration for Jenkins is the following:
# Just to redirect HTTP to HTTPS
<VirtualHost *:80>
ServerName jenkins.mydomain.com
ServerAlias www.jenkins.mydomain.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<Virtualhost *:443>
ServerName jenkins.mydomain.com
ServerAlias https://jenkins.mydomain.com
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Proxy https://localhost:8443/jenkins*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /jenkins http://localhost:8443/jenkins nocanon
ProxyPassReverse /jenkins http://localhost:8443/jenkins
ProxyPassReverse /jenkins http://jenkins.mydomain.com/jenkins
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
RequestHeader set X-Forwarded-Ssl on
RewriteEngine on
RewriteRule "^/$" "/jenkins/" [R]
SSLEngine on
SSLCertificateFile path/to/fullchain.pem
SSLCertificateKeyFile path/to/privkey.pem
</Virtualhost>
However, with this configuration I get an error 502 (Proxy Error):
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /jenkins/.
Reason: Error reading from remote server
The 502 you're getting is because Apache isn't receiving a response from http://localhost:8443/jenkins. This is the first issue that needs to be resolved before anything else can work. Ensure that you are able to access Jenkins by utilizing cURL.
For example: curl http://localhost:8443/jenkins if no response then try curl https://localhost:8443/jenkins if no response there, then I'd take a look and see if Jenkins is configured properly.
There are a couple things I did notice that should be updated in your Virtual Host configuration.
ServerAlias https://jenkins.mydomain.com should be ServerAlias www.jenkins.mydomain.com as https:// should not be included in a ServerAlias directive, plus you may want to be able to get to the site using https://www.jenkins.mydomain.com since that's in the non-https directive. You also most likely will want to include a rewrite in your https virtual host that rewrites www.jenkins.mydomain.com to jenkins.mydomain.com.
You probably don't need the second ProxyPassReverse directive.