|
24 | 24 | - [Hardware Acceleration - Intel GPU](#hardware-acceleration---intel-gpu)
|
25 | 25 | - [Samba](#samba)
|
26 | 26 | - [HTTPS](#https)
|
| 27 | + - [Self Signed SSL](#self-signed-ssl) |
| 28 | + - [Reverse Proxy](#reverse-proxy) |
| 29 | + - [Apache2](#apache2_reverseProxy) |
| 30 | +- [Firewall](#firewall) |
| 31 | + - [Hints for NAT via `ufw`](#hints-for-nat-via-ufw) |
| 32 | + - [Setup](#setup_ufw) |
27 | 33 |
|
28 | 34 | <a name="os"></a>
|
29 | 35 | # Choice of OS
|
@@ -606,8 +612,154 @@ sudo systemctl enable smbd.service nmbd.service
|
606 | 612 |
|
607 | 613 | # HTTPS
|
608 | 614 |
|
609 |
| -It is important to know that every client software that I know can't handle self signed SSL certificates. Other users have the same problem here. So I would say if you want to use HTTPS you have no choice but to make a certified SSL certificate. For that you can use `certbot`. |
| 615 | +It is important to know that every client software that I know can't handle self signed SSL certificates. Other users have the same problem here. As example the Jellyfin and Suwayomi client software has no possibility to connect via HTTPS if the SSL certificat is self signed. So I would say if you want to use HTTPS you have no choice but to make a certified SSL certificate. For that you can use `certbot`. But a downside by using `certbot` is that the SSL certs expire pretty fast and have to be newly generated because if not we have the same problem as with the self signed ones. The client software doesn't connect via HTTPS. **But** if the wished service (like Suwayomi) is only used via the web browser that problem is no more. For that I use `openssl` to generate a self signed SSL cert. |
610 | 616 |
|
611 |
| -Or you make a reverse proxy. The scenario is that Jellyfin uses a self signed SSL certificate and your desktop binds that connection locally over HTTP using Apache2 or something like that. |
| 617 | +I you want to setup HTTPS for a working HTTP website you can either add the generated SSL certificate or if not possible through a *reverse proxy*. |
612 | 618 |
|
613 |
| -But that would only workout for devices that can bind the HTTPS connection locally on a local HTTP side. So mobile devices would have trouble with that. |
| 619 | +## Self Signed SSL |
| 620 | +
|
| 621 | +Generate a self signed SSL certificate using `openssl` that expire after one year. The duration until the certificate will expire can be changed. |
| 622 | +
|
| 623 | +```bash |
| 624 | +#!/bin/bash |
| 625 | +sudo apt install openssl |
| 626 | +# generate ssl cert |
| 627 | +openssl req -x509 -newkey rsa:4096 -keyout ssl-selfsigned.key -out ssl-selfsigned.crt -days 365 -nodes |
| 628 | +``` |
| 629 | +
|
| 630 | +The `-x509` stands for a self signed cert. `rsa:4096` sets the encryption method to RSA 4096 Bit. Change `-days DURATION` to a wished duration how long the cert should be valid. `-nodes` declares that no password based encryption should be used for the private key. Pretty useful so you don't have to enter the password for starting Apache2 as a service. |
| 631 | + |
| 632 | +## Reverse Proxy |
| 633 | + |
| 634 | +The scenario is that you have a web service that doesn't support HTTPS directly. Here you use a self signed SSL certificate and Nginx or Apache2. Now setup one of them to pass the HTTPS requests locally to the HTTP service and that's it. Basicly we tunnel locally the original HTTP web service to another web service that uses HTTPS. Additionally you can forbit the HTTP port to be used by external clients directly so the only way is through the HTTPS web service that tunnels the request to the original one. For that you can use `ufw` or maybe something like that is already possible by the HTTP service itself. |
| 635 | + |
| 636 | +<a name="apache2_reverseProxy"></a> |
| 637 | +### Apache2 |
| 638 | + |
| 639 | +Here how to setup Apache2 to setup as reverse proxy. |
| 640 | + |
| 641 | +```bash |
| 642 | +#!/bin/bash |
| 643 | +# setup basic apache |
| 644 | +sudo apt install apache2 |
| 645 | +sudo systemctl enable apache2 |
| 646 | +# enable needed modules |
| 647 | +sudo a2enmod ssl rewrite proxy proxy_http |
| 648 | +``` |
| 649 | + |
| 650 | +Now we add up a site under Apache2 and enable that site. After that it's needed to reload/restart Apache2 to load the enabled modules and it's site. |
| 651 | + |
| 652 | +```bash |
| 653 | +#!/bin/bash |
| 654 | +cd /etc/apache2/sites-available |
| 655 | +sudo nano reverseProxy.conf |
| 656 | +``` |
| 657 | + |
| 658 | +Here an example how the configuration file can look like and works out for me. The adress `http://127.0.0.1:8149` using the port **8149** is the original web page and the tunneled web page through HTTPS is located under the port **8150**. |
| 659 | + |
| 660 | +```bash |
| 661 | +<VirtualHost *:8150> |
| 662 | + SSLEngine on |
| 663 | + SSLCertificateFile /PATH/ssl-selfsigned.crt |
| 664 | + SSLCertificateKeyFile /PATH/ssl-selfsigned.key |
| 665 | +
|
| 666 | + ProxyPreserveHost On |
| 667 | + ProxyPass / http://127.0.0.1:8149/ |
| 668 | + ProxyPassReverse / http://127.0.0.1:8149/ |
| 669 | +</VirtualHost> |
| 670 | +``` |
| 671 | + |
| 672 | +The declared port **4590** for Apache2 has to be mapped within the `/etc/apache2/ports.conf`. Here an example like I did that. |
| 673 | + |
| 674 | +```bash |
| 675 | +#!/bin/bash |
| 676 | +cd /etc/apache2 |
| 677 | +sudo cp ports.conf ports.conf.backup |
| 678 | +sudo nano ports.conf |
| 679 | +``` |
| 680 | + |
| 681 | +And here the `/etc/apache2/ports.conf`. |
| 682 | + |
| 683 | +```bash |
| 684 | +# If you just change the port or add more ports here, you will likely also |
| 685 | +# have to change the VirtualHost statement in |
| 686 | +# /etc/apache2/sites-enabled/000-default.conf |
| 687 | +
|
| 688 | +Listen 80 |
| 689 | +
|
| 690 | +<IfModule ssl_module> |
| 691 | + Listen 443 |
| 692 | + Listen 8150 # reverse proxy |
| 693 | +</IfModule> |
| 694 | +
|
| 695 | +<IfModule mod_gnutls.c> |
| 696 | + Listen 443 |
| 697 | + Listen 8150 # reverse proxy |
| 698 | +</IfModule> |
| 699 | +
|
| 700 | +``` |
| 701 | + |
| 702 | +Now enable the site and restart/reload the Apache2 service. And maybe checkout the **status** of Apache2 if something doesn't work like it should. |
| 703 | +
|
| 704 | +```bash |
| 705 | +#!/bin/bash |
| 706 | +sudo a2ensite reverseProxy |
| 707 | +sudo systemctl restart apache2 |
| 708 | +sudo systemctl status apache2 |
| 709 | +``` |
| 710 | +
|
| 711 | +The website should be reachable via the url `https://IP-ADRESS:8150`. |
| 712 | +
|
| 713 | +# Firewall |
| 714 | +
|
| 715 | +For a firewall setup I use `ufw`. `ufw` will replace `netfilter-persistent` so I would recommend to use `ufw` only for the servers that doesn't use *NAT* (*Network Adress Translation*). This package is a firewall (filters packages) that wraps around `iptables` so basicly you *can* use NAT but you have to put the configuration for `iptables` that should load up by `netfilter-persistent` into the configuration file of `ufw`. |
| 716 | + |
| 717 | +## Hints for NAT via `ufw` |
| 718 | + |
| 719 | +Put the parts that you want to load up (iptables config `/etc/iptables/rules.v4`) into the file `/etc/ufw/before.rules`. So the configuration will load up as before. |
| 720 | + |
| 721 | +<a name="setup_ufw"></a> |
| 722 | +## Setup |
| 723 | + |
| 724 | +Here a basic setup for `ufw` so every request from outside that is not allowed spezifically will be blocked. |
| 725 | + |
| 726 | +```bash |
| 727 | +#!/bin/bash |
| 728 | +sudo ufw default deny incoming |
| 729 | +sudo ufw default allow outgoing |
| 730 | +``` |
| 731 | + |
| 732 | +Now allow SSH before load up the firewall. If loaded before SSH is allowed the connection will break and you will lose potentially your server access. |
| 733 | + |
| 734 | +```bash |
| 735 | +#!/bin/bash |
| 736 | +sudo ufw allow 22/tcp # or simply *allow ssh* if port is default |
| 737 | +sudo ufw enable |
| 738 | +``` |
| 739 | + |
| 740 | +Last but not least adding every service (port) that should be reachable from outside. |
| 741 | + |
| 742 | +```bash |
| 743 | +#!/bin/bash |
| 744 | +# own dns setup |
| 745 | +sudo ufw allow 53 |
| 746 | +sudo ufw allow 5335 |
| 747 | +# dhcp, hostapd, samba & jellyfin |
| 748 | +sudo ufw allow 67/udp |
| 749 | +sudo ufw allow 68/udp |
| 750 | +sudo ufw allow Samba |
| 751 | +sudo ufw allow 8096/tcp |
| 752 | +sudo ufw allow 8920/tcp |
| 753 | +# reverse proxy & web services |
| 754 | +sudo ufw allow 80/tcp |
| 755 | +sudo ufw allow 445/tcp |
| 756 | +sudo ufw allow 8150/tcp |
| 757 | +``` |
| 758 | + |
| 759 | +And reload `ufw` to get the changes working and checkout the status of `ufw`. |
| 760 | + |
| 761 | +```bash |
| 762 | +#!/bin/bash |
| 763 | +sudo ufw reload |
| 764 | +sudo ufw status |
| 765 | +``` |
0 commit comments