1

I want to access my website via virtual host from the internet. For now, I am using the public IP address of my server to access my website. Here is what I am using (please see below).

http://122.4.195.12:7777/site/index.php

  1. Is there a way to access my virtual host from the internet? When I am accessing my virtual host from my internet (https://mysite/site/index.php) I am getting

DNS_PROBE_FINISHED_NXDOMAIN error
mysite’s server IP address could not be found.

  1. Is there a way to add a SSL when accessing my website via public IP address? When I change http into https I am getting

ERR_SSL_PROTOCOL_ERROR
122.4.195.12 sent an invalid response.
http://122.4.195.12:7777/site/index.php -> https://122.4.195.12:7777/site/index.php

Here is my Virtual Host Config:

<VirtualHost *:7777>
DocumentRoot "C:\xampp\htdocs"
  ServerName mysite
  <Directory "C:\xampp\htdocs">
    Require all granted
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
<VirtualHost *:443>
     DocumentRoot "C:/xampp/htdocs"
     ServerName mysite
     SSLEngine on
     SSLCertificateFile "crt/scratchitsite/server.crt"
     SSLCertificateKeyFile "crt/mysite/server.key"
     <Directory "C:\xampp\htdocs">
        Require all granted
        AllowOverride All
        Order allow,deny
        Allow from all
      </Directory>
 </VirtualHost>

Here is the host file of my server:

127.0.0.1       mysite

1 Answers1

0

For question 1

The easier way will still be registering a domain name, point it to your IP address, and setup your VirtualHost ServerName for it

The VirtualHost actually detecting the Host HTTP Header from server site, so the key thing here is:

How to make the client browser send the Host header the same with you defined on server

For example, by using CURL you can force it to use the user definied Host header like this: curl -H 'Host: mysite' 122.4.195.12:7777/site/index.php

If you're using Chrome, you can try to use a browser extension, like this

For question 2

You've enabled HTTPS on port 443 instead of 7777 in your Apache configuration

Which means you should access your HTTPS service like this https://122.4.195.12:443/site/index.php instead of this https://122.4.195.12:7777/site/index.php

Mech Tsai
  • 190
  • 6
  • How can I enable https of 7777? –  May 15 '19 at 04:15
  • I added the chrome extenstion what do I put in the source hose and virtual host? –  May 15 '19 at 04:17
  • You can't enable HTTP and HTTPS to a same port (e.g. 7777) at the same time, they must be different. And for the extension, put your IP address on the source host and the virtual host is your domain name (e.g. mysite) – Mech Tsai May 15 '19 at 04:34
  • So what will I do in my virtual host to enable https? can you show me I am a little confused –  May 15 '19 at 04:43
  • You already did it, in the section `` has a `ServerName` directive in it – Mech Tsai May 15 '19 at 05:12
  • Oh ok now I have another problem when I access the site using :443 I am getting "privacy error NET::ERR_CERT_AUTHORITY_INVALID" –  May 15 '19 at 05:14
  • You might signed the SSL certificate yourself, to avoid this warning, the certification mush be signed from a verified CA. You can consider LetsEncrypt for this, but you'll need a validated domain name first – Mech Tsai May 15 '19 at 06:03
  • I used it but still not valid –  May 15 '19 at 06:53
  • We'll need more information in this case. What's the domain name you owned? And how LetEncrypt verify your ownership of the domain when signing the certificate for you? And, if this is only for developing purpose, you can consider just simply ignore this warning. – Mech Tsai May 15 '19 at 07:05
  • I dont have a domain. but I need to access my site via https –  May 15 '19 at 07:09
  • As I said, to sign the SSL certificate from CA you'll need a valid domain name. And, the ERR_CERT_AUTHORITY_INVALID is a warning, you can ignore it from browser for developing purpose, see: https://superuser.com/questions/1083766/how-do-i-deal-with-neterr-cert-authority-invalid-in-chrome – Mech Tsai May 15 '19 at 07:13
  • Simply Google for it, `letsencrypt xampp` and you'll get many tutorials for this. But again, you'll need a valid domain name before you try to apply LetsEncrypt SSL certificate to your site. For developing purpose, this is really not necessary, since you'll need to renew the LetsEncrypt certificate every 3 month when using it's free plan. – Mech Tsai May 15 '19 at 08:49
  • I have a subdomain now how can I install the ssl? –  May 16 '19 at 05:58
  • Try this: https://www.docketrun.com/blog/how-to-setup-lets-encrypt-for-apache-on-xamp-wamp-in-windows-vm/ – Mech Tsai May 16 '19 at 06:11
  • Do install SSL manually into Xampp Apache, would be something like this: https://gist.github.com/nguyenanhtu/33aa7ffb6c36fdc110ea8624eeb51e69 – Mech Tsai May 16 '19 at 06:18