Score:1

Ubuntu 20.04 Redirect HTTP to HTTPS

ua flag

Raspberry PI running Ubuntu 20.04 hosting a dotnet 6 (core) web application. DotNet by default listens to port 5000 (HTTP) and port 5001 (HTTPS). I can get http://mydomain to work but I CANNOT get HTTPS to work. My Program.cs file is set to for UseHttpsRedirection (Which works on localhost)

Note: I developed webapp on my local machine, published and deployed web app to Ubuntu (Raspberry PI) Here is my config file

<VirtualHost *:80>
   ServerName me.com
   ServerAdmin [email protected]
   Redirect "/" https://me.com
   ErrorLog ${APACHE_LOG_DIR}/error-me.com-ssl.log
   CustomLog ${APACHE_LOG_DIR}/access-me.com-ssl.log combined
</VirtualHost>

<VirtualHost *:443>
   ServerName me.com
   DocumentRoot /var/www/me.com
   ProxyPreserveHost On
   ProxyPass / https://127.0.0.1:5001/
   ProxyPassReverse / https://127.0.0.1:5001/
   SSLEngine on
   SSLCertificateFile "/etc/ssl/certs/server.me.com.crt"
   SSLCertificateKeyFile "/etc/ssl/private/server.me.com.key"
</VirtualHost>
guiverc avatar
cn flag
If you're asking about Ubuntu 20.04, why have you tagged your question as being about Ubuntu 12.04? Please correct.
it flag
What doesn't work? The redirection, or SSL completely? What URL/Ports are you trying? What errors are you getting?
DavidJS avatar
ua flag
If I use VirtualHost *:80 and use ProxyPass / http://127.0.0.1:5000, then it works because the app listens on port 5000. Then I turned on HTTPSRedirect and changed VirtualHost 80 to redirect to VirtualHost 443. When I go to enter the public domain/IP address the browser just shows "This site can’t be reached"
pa4080 avatar
cn flag
What happens if you use port 5000 with the same nonfiguration?
DavidJS avatar
ua flag
@pa4080 - What do you mean? I tried using http:'//127.0.0.1:5000 on <VirtualHost *:443> and I still get "This site can’t be reached"
DavidJS avatar
ua flag
I turned off app.UseHttpsRedirection() from Program.cs, published/deployed then accessed my URL with HTTP worked. Then I accessed the site with HTTPS and again "This site can’t be reached". So maybe SSL is not setup correctly?? I created a self-signed certificate using command: sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/server.yourdomain.com.key -out /etc/ssl/certs/server.yourdomain.com.crt
DavidJS avatar
ua flag
I get this error when I do a CURL https://localhost:5001, (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.haxx.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it
Nmath avatar
ng flag
Looks like you're using a virtualhost file for apache2. Is it installed and configured? Do you have a SSL certificate and are the paths correct?
pa4080 avatar
cn flag
Hi, @DavidJS, first of all you need to confirm your HTTPS Virtual Host works properly. Create the DocumentRoot directory with simple index.html file inside... and check these answers: https://askubuntu.com/a/893406/566421 and https://askubuntu.com/a/900433/566421. And the Cerbot's instructions page: https://certbot.eff.org/instructions?ws=apache&os=ubuntufocal
DavidJS avatar
ua flag
@Nmath - I am using a virtualhost and I have confirmed that its listening on PORT 80 and 443. I only have a self-signed certificate I created with openssl and I did confirm the paths. I will try out LetsEncrypt and see if that makes a difference.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.