1

I self host two websites on a Apache2 instance that runs on a Raspberry Pi3 (more info on versions and configurations below): Website1 is a a static website that I coded from scratch, while website2 runs on Wordpress.

I used to live in an apartment where the ISP provided a static public IP but I recently moved to a new house, where the ISP does not provide that option. I have been trying to reconfigure everything but I cannot make it all work again.

Configurations

I have a Raspberry Pi 3 running the latest version of Raspbian

$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

On my router (model: Alcatel-Lucent G240W-B) I have opened port XX for http and port YY for ssh (I am not using standard ports to increase security)

Application Name | WAN Connection | WAN Port | LAN Port | Internal Client | Protocol | Status
Customer settings | {my_wan_connection} |   XX~XX | XX~XX | 192.168.1.100 | TCPorUDP | ACTIVE
Customer settings | {my_wan_connection} | YY~YY | YY~YY | 192.168.1.100 | TCPorUDP | ACTIVE

I am running apache2

$ apache2 -v
Server version: Apache/2.4.25 (Raspbian)
Server built:   2019-08-19T19:25:31

with two websites enabled

$ sudo apache2ctl -S
VirtualHost configuration:
*:XX                 is a NameVirtualHost
         default server mydomain.ddns.net (/etc/apache2/sites-enabled/website1.com.conf:1)
         port XX namevhost mydomain.ddns.net (/etc/apache2/sites-enabled/website1.com.conf:1)
                 alias website1.com
                 alias www.website1.com
         port XX namevhost mydomain.ddns.net (/etc/apache2/sites-enabled/website2.com.conf:1)
                 alias www.wesbiste2.com
                 alias wesbiste2.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: MODSEC_2.5
Define: MODSEC_2.9
User: name="www-data" id=33
Group: name="www-data" id=33

This is my ports.conf

$ sudo cat ports.conf 
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 0.0.0.0:XX

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

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

The /etc/apache2/sites-enables/website1.conf


<VirtualHost *:XX>
        # 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 email@mailhost.com
        ServerName mydomain.ddns.net
        ServerAlias website1.com
        ServerAlias www.website1.com
        DocumentRoot /var/www/website1/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
</VirtualHost>

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

And the The /etc/apache2/sites-enables/website2.conf

<VirtualHost *:XX>
        # 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 mail2@mailhost.com
        ServerName mydomain.ddns.net
        ServerAlias www.website2.com
        ServerAlias website2.com
        DocumentRoot /var/www/website2/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
</VirtualHost>

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

I have set a dynamic DNS with NoIP (mydomain.ddns.net) which gets updated through my router

What works and what does not

  • SSH works fine, and I can connect to my raspberry pi both within my home network and from outside - when I check if door YY is open from a port checking tool I get a positive response

  • HTTP is more problematic: despite the door being closed (according to port checkers at least) I can see website1 (which is apache's default server) from

    • internal ip address: 192.168.1.100:XX
    • public ip address: {my-public-ip}:XX
    • dynamic dns hostname mydomain.ddns.net

However, since in this ways I can only access website1, and not website2, I tried to disable website1 (sudo a2dissite website1.com.conf) and restart apache (sudo systemctl restart apache2)

$ sudo apache2ctl -S
VirtualHost configuration:
*:XX                 mydomain.ddns.net (/etc/apache2/sites-enabled/website2.com.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
Define: MODSEC_2.5
Define: MODSEC_2.9
User: name="www-data" id=33
Group: name="www-data" id=33

However, I still cannot access website2 from internal or public ip, nor DDNS hostname.

Changing Wordpress URL

I thought this might be related to Wordpress and indeed I found this article and followed the instructions to [change the URL directly in the database][2]. Indeed the 'home' and 'url' values were equal to my old public static IP so I changed the to my DDNS (myhostname.ddns.net). However, the site is still unaccessible

FYI, my first priority would to be able to access website2 and see its contents, whether through internal or external IP, or DDNS hostnmae.

0

So I think I get it... maybe... The trouble might be the way you are testing this. On the computer you are using to test (not the RPi), edit your host file to point both www.website1.com and www.website2.com to your RPi's internal IP address (while you are on the same network).

Instructions on hosts file: https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

Then point your browser to www.website1.com and then to www.website2.com.

If that works, change your hosts file to point those websites to your external IP address.

Explanation: Part of the handshake between the web browser and the web server includes what site you are asking for. This allows more than one site to be hosted on the same web server. As your Apache config states the aliases as www.website1.com and www.website2.com but you are asking for the web site for your IP address. Apache responded with www.website1.com because that is set as your default site.

  • If I can be so bold: If these are related web sites, but you made them separate only because part is WP and the other is not... maybe it would be worth the effort to fit all your links to restructure the whole thing... Rather that custom content on www.website1.com and WP on www.website2.com, put your custom content on www.website.com/ and the WP content on www.website.com/wp/. If that makes sense for your project, here is info on how to move WP: manage.accuwebhosting.com/knowledgebase/2398/… – Art Hill Sep 20 at 20:31
  • I forgot to say: You should remove the changes to your hosts file when you are done. Once your external IP address changes, your computer will continue to point to the same IP address if you do not. – Art Hill Sep 20 at 20:40
  • No, the two websites are not related at all. One is my personal page and the other is something I created with a team of people on a completely unrelated project. I tried your first suggestion and changed the /etc/hosts file on the laptop I use to control the RbPi by adding the lines 192.168.1.100 www.website1.com and 192.168.1.100 www.website2.com. Unfortunately it did not work... I also tried to add the port number to the IPs (that is 192.168.1.100:8080) but still nothing. That said, thank you for the suggestion and the links! Still managed to learn something :) – Fede9390 Sep 20 at 20:59
  • Well poop. The parts of your Apache config you have shared look to me as missing things. In particular, you need separate "DocumentRoot" for each web site, but I dont see that above. Now, I only mess with Apache on Centos, so it is a bit different... but I think you should have each web site have it's own vhost configured. The WP one should look something like: linode.com/docs/websites/cms/… – Art Hill Sep 20 at 21:16
  • If you refer to the output of apache2ctl -S that's just the status of the apache2 server, to show both sites are enabled, have the same ServerName but different ServerAlias. I cannot post my VirtualHost configurations but can add them later. However as I said everything worked fine before moving and, as far as I understand, VirtualHosts should not change except for ServerName – Fede9390 Sep 20 at 21:30
0

In the end it was the router configuration: the incoming port (WAN port) should be set to 80, and the internal port (LAN port) to whatever port my router is listening to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.