Redirect to https using ngrok - ngrok

Hi i am using ngrok to serve my web application hosted in Apache tomcat running on my machine. I am following commamd to run ngrok
ngrok tls -region=us -hostname secure.example.com -key mydoamin.key -crt mydoamin.crt 80
Its works fine in HTTPS but when i access my domain using http it says Tunnel secure.example.com not found. I think by using tls it is only exposing https what i want is to redirect user from HTTP to HTTPS. Can i achieve this using ngrok?

I hope that you have found a solution to your problem.
Here my solution.
To use it, you must have your certs.
ngrok.yml
authtoken: <your token>
region: <your region>
tunnels:
<name-https>:
addr: 8443
crt: path/to/cert/cert.pem
key: path/to/key/key.pem
host_header: "rewrite"
proto: tls
hostname: www.myexample.test
<name-https>:
addr: 80
proto: http
bind-tls: false
hostname: www.myexample.test
Navigate to the directory /etc/apache2/sites-available and create a new file nano example.conf
<VirtualHost *:80>
ServerName myexemple
Redirect permanent / https://www.myexample.test
</VirtualHost>
<VirtualHost *:8443>
ServerName <servername>
DocumentRoot /var/www/html/<your-project>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save all and start the commands:
a2ensite example.conf
systemctl reload apache2
Reach the location of your ngrok.yml file and start it with the command:
ngrok start --all
Try it and have fun :)

Related

Issue with Apache2 Reverse proxy

I need to create a reverse proxy in apache2 for an icecast server, but with another virtualhost as a simple website
I managed to create the reverse proxy, using this configuration in apache Virtualhost
<VirtualHost 100.100.100.100:80>
ServerName icecast.xxx.com
ProxyPass / http://localhost:8000/
</VirtualHost>
100.100.100.100 is the ip of the server, and xxx.com is the domain
So when i type in my browser icecast.xxx.com the icecast admin panel (on 8000 port) show up
Then i have added another virtualhost
<VirtualHost *:80>
ServerName xxx.com
ServerAlias www.xxx.com
ServerAdmin MY_EMAIL
DocumentRoot /var/www/site/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have enabled him with sudo a2ensite NAME_OF_THE_CONFIG_FILE
But when I go to the ip of the VPS or to xxx.com/www.xxx.com the icecast2 admin panel show up!
I don't know how to solve this, I maybe think that the error is in the line
I finally managed to solve the issue,
simply in the reverse proxy virtualhost, instead of <VirtualHost 100.100.100.100:80>
I need to put
<VirtualHost *:80>

Redirect on HAProxy

I'm trying to replicate the following configuration made in apache in HAProxy, but so far without success.
<VirtualHost *:80>
ProxyPreserveHost On
ServerName alpha.app.int
ProxyPass / http://127.0.0.1:8080/app/
ProxyPassReverse / http://127.0.0.1:8080/app/
</VirtualHost>
What I'm trying to do is when the address 'alpha.app.int' is accessed, HAProxy automatically directs all requests for my application in JBoss that is listening on '127.0.0.1:8080/app/', but when I try to access through the url previously mentioned I end up falling on the configuration screen of JBoss and not in my application, I can only see it by accessing 'alpha.app.int/app/'. Does anyone have any suggestions on how to do this?
HAProxy Settings:
frontend app
bind *:80
mode http
default_backend frontend app
backend app
mode http
option forwardfor
server alpha 127.0.0.1:8080/app
You can try that :
frontend app
bind *:80
acl path_root path /
redirect location https://www.example.com/app/ if path_root
default_backend app
backend app
mode http
option forwardfor
server alpha 127.0.0.1:8080

How to trace site route in apache

UBUNTU + APACHE
I am running a few wordpress sites on one server (that I inherited) using VirtualHosts, and I need to configure ssl certificates for each site.
Before starting to set up certificates for each site, I tried entering each domain with the https prefix on the browser and noticed it redirects me to a site (with an invalid certificate) that is supposed to be disabled and does even show up when I run
apachectl -t -D DUMP_VHOSTS
I tried configuring the virtualhost entries for one of the sites with the valid certificate and it still goes to same old site. How can I completely disable and remove that site and the invalid certificate? I cannot find it anywhere on the server.
My Virtual host looks something like this
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.yoursite.com
DocumentRoot /var/www/site
SSLEngine on
SSLCertificateFile /path/to/www_yoursite_com.crt
SSLCertificateKeyFile /path/to/www_yoursite_com.key
SSLCertificateChainFile /path/to/DigiCertCA.crt
</VirtualHost>
If you want to disable a virtual host configuration you just need to do:
sudo a2dissite sitename
sudo systemctl restart apache2
and the issue should be resolved

Apache2 redirect to https

For one of my customer projects, I have a domain name abc.my-app.com. My server public IP is x.y.z.a .
I have developed a Spring boot based application. In the application, I have configured automatic redirect from http port 8088 to https 8443.
The application is accessible as https://x.y.z.a:8443/ without issues.
The application is also redirected to https when accessed as http://x.y.z.a:8088
in the browser.
Refer https://drissamri.be/blog/java/enable-https-in-spring-boot/ on how I have configured this.
I also have setup apache 2.4.18 version on my server. I have configured virtual hosts to be able to redirect to https when my application is accessed from browser as https://abc.my-app.com to https://abc.my-app.com:8443.
But, if user accesses http://abc.my-app.com (without https), the apache does not redirect to my application on https.
How do I enable Apache to redirect from http://abc.my-app.com to https://abc.my-app.com?
My Virtual host configuration is below:
<VirtualHost *:80 *:8080 *:443>
ServerAdmin webmaster#xyzc
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName Off
ProxyPreserveHost On
# Servers to proxy the connection, or
# List of application servers Usage
ProxyPass / https://x.y.z.a:8443/
ProxyPassReverse / https://x.y.z.a:8443/
ServerName ip-x-y-z-a
</VirtualHost>`
I finally got it working. Not sure though this is the right way.
In Spring boot application, I configured redirect from port 80 to port 443.
Apache2 redirects from 443 to my application running on port 8443.

Can't find deployed app

I deployed my first meteor app on a digital-ocean droplet using mup. So it's there but I can't figure out what I still have to setup to actually view my app. So when I go to www.example.com I should see it but all I see is an apache page.
When you start a Meteor app, you can specify the port for it to listen on using the --port argument. For it to be available from at you domain name specify port 80. Though if you have Apache listening on that port already it will fail to bind to it. Uninstall or stop Apache, and restart your Meteor app.
If you are using Apache to serve other content and can not stop it, you'll need to have your Meteor run on a different port with an Apache ProxyPass. First enable mod_proxy and mod_proxy_http
sudo a2enmod proxy proxy_http
Then create a new VirtualHost for the Meteor app that proxies request to the port you have decided to have it listen on. It will look something like:
<VirtualHost *:80>
ServerName www.example.com
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
See this article for all the details.

Resources