I posted this question before but I guess it wasn't clear the way I wrote it or something. So I deleted it and here it is again with as much info as I can think of.
I created a server using old computer parts of a dell dimension 2400. I installed Ubuntu 16.04.6 LTS with Linux 4.15.0-72-generic kernel. I installed mysql-server, apache2, certbot, pyton3, python-apache-certbot, php7.0, ssh, vsftpd and then forwarded the required ports for what I installed to the internal ip. (192.168.1.23).
Then I setup a wordpress site on the server. The problem is I setup the virtual host file (can be seen below) but for the site to work I have to use the network internal ip for the site to load.
Here is the virtual host file:
<IfModule mod_ssl.c>
<VirtualHost 192.168.1.23:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/domain.com/public_html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ServerName domain.com
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
~
Keep in mind this is the working virtual host.
When I change this to the domain name (domain.com:443) as it should be it doesn't work.
(Same issue on port 80.)
Do I need an internal dns or is it something else?
I tried installing bind but either I botched it up horribly or it wasn't the case ... or both ... leaning more toward both honestly.
anyway I hope this is enough info and someone is able to shed some light on this. I would like to be able to host another site on this server.
The
ServerName
directive is used in order to define the default domain name that will be accepted by the virtual host (andServerAlias
for the synonymous of the default domain name). Also you do not need to specify network interface IP adders (or a domain name) within the<VirtualHost>
tag, while you are doesn't have any special goals - i.e. serve different content for the same domain name accessed by different server's IP addresses, etc.Unless there is not FQDN that points to your server's public IP address, you need to setup a local DNS or you need to edit the
hosts
files of your LAN devices in order to access your (web) server by a domain name within the LAN. For more details, please read the following references:Apache2 Docs: Name-based Virtual Host Support
Creating additional Virtual Host Ubuntu Server
How to set a domain to ip address?
Setting up vhost on VirtualBox with Ubuntu 16.04
apache virtual hosts not working
The
ServerName
directive is only used by Apache to know what domain it's running as (and in some cases it's used to differentiate between multiple VirtualHosts depending on the domain). It does have no effect on clients trying to resolve the domain.What changes you need to make entirely depends on what your setup is looking like.
If you want to use a domain, you still need to tell the client computers what PC it points to. This can either be done through the system's
hosts
-file (easier to setup, especially for testing, but is a hassle to setup for each and every computer) or through your own DNS Server (a bit harder to setup and to get right, but more flexible in the end). (This doesn't apply if you are using an "official" domain, not something you invented yourself. Unless you want to resolve domain.com to your internal IP while in your local network.)To check if the domain itself is setup correctly, check your public IP (or the local IP through
ifconfig -a
, depending on your setup) on the server through a page like ifconfig.co and compare it to the IP returned by eitherdig domain.com
ornslookup domain.com
. If they return the same, your domain is correctly set up to point to your public IP. If they don't, you will have to change where your domain points to, but I can't really help with that.If you want to access the page from the public internet, you will have to worry about NAT. NAT (or "Network Address Translation") handles communication of multiple internal devices through a single public IP (it's likely that a similiar thing is set up in your case). Your router currently has no idea what computer it should send incoming packets on port 80/443 to, which might be one possible cause of your issues. To set it up correctly, search for how to setup "Port Forwarding" on your specific router, and set it up so that it sends all incoming TCP packets on port 80 and 443 to the same port on your server in the local network.
You also might need to pay attention to the VirtualHost directive, where you specifically put your local IP (although I can't imagine it being an issue in your current setup, the other causes are more likely). This basically tells Apache to only ever listen to incoming connections on that specific IP. Once you set up NAT, this should be fine, since requests are sent to your local network's interface. In case you still run into issues after working through the other steps, you might want to try substituting that IP address with an asterisk, causing Apache to listen on all interfaces. This would remove another (if very small) cause of possible errors.
So after a lot of time and research I figured it out. There were many issues but the main resolution was for example it would be
<virtualhost 192.168.1.23 askubuntu.com:80>
This is working now with multiple virtual hosts.I did have some issues serving http over port 443 and other issues. I wound up reformatting the entire disk and reinstalling everything after I figured this out.
Running like a charm now!
Thanks for all the help!