Apache couldn't determine servername on docker container - apache

I am trying to set up a customized docker container for an existing site. To do so I want to provide my own custom vhost configuration with a ServerName.
But when I try to add a custom vhost configuration and restart apache I get the warning that Apache was unable to determine the global name: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message
What's important is the fact that when I log into container's shell and manually run service apache2 restart I do not get this warning anymore.
How can I suppress that on the build? Should I provide the vhost to the composer somehow else?
Here is my docker-compose.yml is like:
version: '3'
services:
web:
build:
context: ./etc/php
args:
- APP_HOST=${APP_HOST}
ports:
- ${APP_PORT}:80
- ${APP_PORT_SSL}:443
volumes:
- ./var/bin/:/tmp/bin/
- ./app/:/var/www/html/
- ./log/:/var/log/
- ./etc/php/conf/:/usr/local/etc/php/conf.d/
environment:
- VIRTUAL_HOST=${VIRTUAL_HOST}
Then, Dockerfile that adds my own available site:
FROM php:7.0-apache
ENV TERM=xterm
LABEL maintainer="Derek P Sifford <dereksifford#gmail.com>" \
version="0.15.2-php7.0"
ARG APP_HOST
ENV APP_HOST=$APP_HOST
ADD ./sites/app.conf /etc/apache2/sites-available/app.conf
RUN sed -i 's/ServerName APP_HOST/ServerName '$APP_HOST'/g' /etc/apache2/sites-available/app.conf
RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf \
&& a2enmod rewrite expires \
&& a2dissite 000-default.conf \
&& a2ensite app.conf \
&& service apache2 restart
WORKDIR /app
EXPOSE 80 443
And obviously site config:
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName APP_HOST
SetEnv APPLICATION_ENV "development"
<Directory "/var/www/html">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

As indicated here and in the warning message you can set the ServerName property to localhost in /etc/apache2/apache2.conf from within the Dockerfile.

I think there is a problem with your configuration, because you copy it and mount it on a volume. I think your configuration should not evolve when your container is live, so you don't need to mount it.
So, try to remove this line from your docker-compose.yml :
- ./etc/php/conf/:/usr/local/etc/php/conf.d/

On your apache container instance, you should put IP 172.26.0.2 in /etc/hosts and provide a fully qualified name to it e.g.
172.26.0.2 vbox.test.com
Then replace hostname with vbox.test.com
or
put localhost in serverName.
This should help you.

Related

How to add a domain name in local with Apache?

I have a website which I used to deploy in localhost running the command: sudo /etc/init.d/apache2 start and then typing the URL: http://XXX/myfirstphpsite/src where XXX is my IP address and myfirstphpsite/src the repertory containing my website.
However, now I want to type the following URL:
http://pharaohohparis.tld instead of the last URL to deploy in local my website.
For that, I did the following:
I went to the repertory: /etc/apache2/sites-available/ and created a new file named: pharaohofparis.tld.conf in which I inserted:
<VirtualHost *:80>
ServerName pharaohofparis.tld
DocumentRoot /var/www/html/myfirstphpsite/src
<Directory /var/www/html/myfirstphpsite/src>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I actived the virtual host by typing:
sudo a2ensite pharaohofparis.tld.conf
sudo service apache2 reload
I edited the file /etc/hosts by adding the line:
127.0.0.1 pharaohofparis.tld
However, when I type the URL: http://pharaohofparis.tld, I got the DNS error "DNS_PROBE_FINISHED_NXDOMAIN". How can I fix this ?
EDIT: THE PROBLEM WAS LINUX SUBSYSTEM. THERE WAS NO PROBLEM IS A REAL UBUNTU.
As I said in my Edit above: the problem was apparently Linux Subsystem. There was no problem is a real Ubuntu.

Host Multiple Domains on One Server/IP

I have phpList already setup and Codeigniter project that I want to add in one server.
The phpList configuration which is located /etc/httpd/conf.d/phplist.conf has:
<VirtualHost *:80>
ServerName phplist.example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/phplist-3.0.5/public_html
LogLevel warn
ErrorLog /var/log/httpd/phplist_error.log
CustomLog /var/log/httpd/phplist_access.log combined
</VirtualHost>
Here is my possible setting for the CI project, but I don't know how to create one.
<VirtualHost *:80>
ServerName listcsv.com
ServerAdmin admin#listcsv.com
DocumentRoot /var/www/citest/index.php
</VirtualHost>
Below the /etc/httpd/conf/httpd.conf file has a IncludeOptional conf.d/*.conf so I think this would include the configuration file on phplist.
I don't know what settings and where configuration file should I go,
should I edit on /etc/httpd/conf/httpd.conf or just add it together with the phpList configuration at /etc/httpd/conf.d/phplist.conf?
I tried accessing phplist at http://phplist.example.com but the site cannot be reached.
I could access the phpList by going to http://server-ip-address/lists/admin on the browser.
Also, I cannot access the CI project.
I would recommend creating the directory that the virtual hosts will be stored in, as well as the directory that tells Apache that a virtual host is ready to serve the website
sudo mkdir /etc/httpd/sites-available # vhost files
sudo mkdir /etc/httpd/sites-enabled # symbolic links for vhost enabled
Tell Apache where to look for virtual hosts
sudo vim /etc/httpd/conf/httpd.conf
Add this line at the end of the file
IncludeOptional sites-enabled/*.conf
Save and exit.
For each website/domain create its own vhost
sudo vim /etc/httpd/sites-available/example1.com.conf
sudo vim /etc/httpd/sites-available/example2.com.conf
sudo vim /etc/httpd/sites-available/example3.com.conf
Enable the virtualhost
sudo ln -s /etc/httpd/sites-available/example1.com.conf /etc/httpd/sites-enabled/example1.com.conf
sudo ln -s /etc/httpd/sites-available/example2.com.conf /etc/httpd/sites-enabled/example2.com.conf
sudo ln -s /etc/httpd/sites-available/example3.com.conf /etc/httpd/sites-enabled/example3.com.conf
We done, restart your Apache server for the changes to take affect
sudo apachectl restart
Don't forget to point your domains to the web server's public IP address.

Apache Virtual Hosts DocumentRoot path

[1] DocumentRoot /var/www/example.com/public_html
[2] DocumentRoot /var/www/example_com/public_html
Which one option is it more preferable? Dotted or underscored?
And once file /etc/apache2/sites-available/example.com.conf is changed, is it needed to re-run also $ sudo a2ensite example.com.conf ? Or change itself is enough? Thanks!
Each option is ok, it's as you want. For my part, on my dedicated server, I'll use example.com syntax.
When you run $ sudo a2ensite example.com.conf for the first time, a symlink is created from /etc/apache2/sites-available/example.com.conf to /etc/apache2/sites-enabled/example.com.conf.
You can change this file at two location, because it's the same file.
If you want to disable your vhost, you should run $ sudo a2dissite example.com.conf

VHost Not Working using AWS AMI httpd

I'm currently creating an application using AWS AMI, and it comes w/ an httpd 2.4.10. Here was the steps I followed on creating the vhost
sudo mkdir /etc/httpd/sites-available
sudo mkdir /etc/httpd/sites-enabled
edited /etc/httpd/conf/httpd.conf to have IncludeOptional sites-enabled/*.conf
created realtydig.conf inside /etc/httpd/sites-available
symlinked it to /etc/httpd/sites-enabled
sudo apachectl restart
sudo service httpd restart
*still the default httpd page is the one showing, vhost not pointing to domain
here's the vhost
xml
<VirtualHost *:80>
ServerName beta.realtydig.com
DocumentRoot /var/www/realtydig/laravel
<Directory "var/www/realtydig/laravel/public">
AllowOverride all
</Directory>
</VirtualHost>
I would like to understand, what happened wrong. It seems to be loading up since error occured w/ some of my previous typos when i was trying to restart the application.
If "nothing happened" then I assume that you see just white empty page in browser. Usually some other vhost will be see if current vhost is not activated.
DocumentRoot must be pointing to the public folder like this
DocumentRoot /var/www/realtydig/laravel/public
You can debug by creating test.html inside the DocumentRoot and try to access it from the browser.

Apache - multiple websites - allow top folder access

I have multiple websites setup on my Apache2 server. The directory structure is as follows:
/var/www/
/var/www/site1.com
/var/www/site2.com
It is setup such that "www.site1.com" has root folder /var/www/site1, "www.site2.com" has root folder /var/www/site2, and http://server_ip_address has root folder /var/www
However, if I type http://server_ip_address/site1.com, it opens site1.com. I don't want this to happen. (That is, individual sites should be accessible only by typing the correct address).
What is the way to configure this. (Also it would be helpful if you could give tips on best practices for directory structures for multiple websites)?
thanks
JP
The VirtualHost directive can be used to set individual DocumentRoots for each site name.
Have also a look at this document:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Configure multiple websites on Ubuntu
Create apache configuration file:
sudo nano /etc/apache2/sites-available/site1.com
Minimal configuration for the virtual host:
<VirtualHost *:80>
DocumentRoot /var/www/site1.com
ServerName www.site1.com
# Other directives here
</VirtualHost>
Create the root folder:
sudo mkdir /var/www/site1.com
Change the permissions of the folder:
sudo chmod -R 775 /var/www/site1.com/
Create a new record in /etc/hosts
sudo nano /etc/hosts
Add the following line:
127.0.0.1 www.site1.com
Create a correct symlinks in sites-enabled:
sudo a2ensite site1.com
Restart the apache:
sudo /etc/init.d/apache2 restart
You have to do the same with the site2.com, site3.com etc...