Andromedae93 Andromedae93 - 4 months ago 9
Apache Configuration Question

Write DNS instead of IP?

I'm working on a project and I would like to make some things in order to be able to handle easier my distant server.

I have a server on which one I installed an API (dolibarr - ERP/CRM software).

This server uses Ubuntu 14.04 and Apache2.

When I want to connect to my software from the net, I open Firefox for example, I write

http://172.30.10.XX
and I am going to the application login page.

But I would like to create a DNS and domain name in order to connect it easier.

For example :

http://shopmoriba.datasystems.fr
instead to write the IP address.

My question is : How I can do that ?

I know that I need to modify some files :
/etc/apache2/sites-available/000-default.conf
or
/etc/hosts
but what I need to write exactly ?

My
/etc/hosts
file looks like :

127.0.0.1 localhost
//127.0.1.1 dolibarr
172.30.10.69 shopmoriba.datasystems.fr

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


My
/etc/apache2/sites-available/000-default.conf
looks like :

<VirtualHost *:80>
# 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/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
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


Thank you by advance

Answer

There should be no need to touch the /etc/hosts on your server.

The important thing to make this owrk is to make the name known to all clients that want to access your application. To do this you basically have two possibiliies:

  1. Add an entry to all /etc/hosts (on windows this is C:\Windows\System32\drivers\etc/hosts) on all clients that are meant to access your application. Doing it this way is not recommended
  2. Add a DNS-record for shopmoriba.datasystems.fr in some DNS-server that will be accessed by all clients that are meant to access the application. If this is solely for internal use go with some DNS-server on your network, perhaps there already is one. If you want to make the application publicly available there is no way around registering an official domain and publishing the hostname via the associated DNS-server.

While you only run one application on your server this will be sufficient. Once you start adding other application that you want to publish under a different hostname you will have to add more <VirtualHost>-sections and add a ServerName-line like

`ServerName shopmoriba.datasystems.fr`

to the respective VirtualHost-configuration.

I ommited the topic of using https since you did not mention you want to use it and especially on servers hosting multiple vhosts it is enough for a separate topic.