4

I want to use my raspberry pi as a webserver. I installed and configured apache and enabled port forwarding on my router, but it seems that I do something wrong. I really searched a lot before, but I can't find an appropriate answer.

Here is what I've done so far:

Apache

ports.conf:

Listen 80

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

apache2.conf

I only added the line

ServerName public_ip

sites-available/default-ssl.conf

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ServerName public_ip:443
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        ServerSignature On
        CustomLog /var/log/apache2/access.log combined
        LogLevel warn
        ErrorLog /var/log/apache2/error.log
</VirtualHost>

I activated the site via

sudo a2enmod ssl
sudo a2ensite default-ssl

iptables

iptables -L

gives me following output:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Netstat

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0     64 192.168.1.12:22         192.168.1.10:30007      ESTABLISHED
tcp6       0      0 :::80                   :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::443                  :::*                    LISTEN

Router Thomson TG782

Port forwarding

enter image description here

Firewall on router

Currently deactivated.

Conclusion

http and https works in the LAN. What am I missing?

3
  • 2
    apache will not understand ServerName with an IP (at least not under a virtual host with *:443. Instead use a proper hostname even if it is just in the /etc/hosts file (e.g. public_ip myserver.mydomain myserver). Moreover, to get inside a virtual host the HTTP request must have the Host: header.
    – grochmal
    Jun 4, 2016 at 16:06
  • 3
    Are you sure your ISP allows default web server ports to go through? Unless you have a static IP, it is very unlikely. One way to test it would be to add another port forwarding rule with a non standard port (such as 8080) in your router that would point to port 80 or your local server and to test it with http://1.2.3.4:8080 (replacing 1.2.3.4 with your public IP). Jun 4, 2016 at 16:11
  • Can you make the conclusion clearer, does it work or not? (like the detail else where) Jun 4, 2016 at 21:03

2 Answers 2

2

With the help of grochmal and Julie Pelletier it works now! (see comments section of my question)

I changed:

ports.conf

Listen 8080

<IfModule mod_ssl.c>
        Listen 8443 https
</IfModule>

sites-available/default-ssl.conf

<VirtualHost *:8443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ServerName server_name_from_hosts_file:8443
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key
        ServerSignature On
        CustomLog /var/log/apache2/access.log combined
        LogLevel warn
        ErrorLog /var/log/apache2/error.log
</VirtualHost>

apache.conf

ServerName server_name_from_hosts_file

Port forwarding

New port forwarding rules for the Ports 8080 and 8443.

Thank you so much!

0

Don't forget to do these two commands.

sudo a2enmod ssl
sudo a2ensite default-ssl

I saw that you only did:

sudo a2ensite default-ssl
1
  • You're correct. I didn't mention it in my original post, but I executed both commands. Thanks for your suggestion, I'll update it Jan 15, 2018 at 23:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .