Skip to main content

Apache WebServer setup

This will show you how to set up and Apache2 config.

Requirements

  • Apache2 WebServer
  • Ubuntu 20.04+

Setup

  1. Install Apache2 on your Ubuntu Server 20.04

    $ sudo apt install apache2
  2. cd into /etc/apache2/sites-enabled

    $ cd /etc/apache2/sites-enabled
  3. Create a new file called example.com.conf

    $ nano example.com.conf
  4. After opening the example.com.conf file, add this. Make sure to replace example.com with your domain name.

    example.com.conf
    <VirtualHost *:443>
    ServerName bpsapi.rajtech.me
    DocumentRoot /var/www/bpsapi.rajtech.me

    <Directory "/var/www/bpsapi.rajtech.me">
    Require all granted
    </Directory>

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =bpsapi.rajtech.me
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    Include /etc/letsencrypt/options-ssl-apache.conf

    SSLCertificateFile /etc/letsencrypt/live/bpsapi.rajtech.me/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/bpsapi.rajtech.me/privkey.pem
    </VirtualHost>
  5. Save the file and exit.

  6. Create a new file in the same directory called example.com-le-ssl.conf

     $ nano example.com-le-ssl.conf
  7. After opening the example.com-le-ssl.conf file, add this. Make sure to replace example.com with your domain name.

    example.com-le-ssl.conf
     <IfModule mod_ssl.c>
    <VirtualHost *:443>
    ServerName bpsapi.rajtech.me
    DocumentRoot /var/www/bpsapi.rajtech.me

    <Directory "/var/www/bpsapi.rajtech.me">
    Require all granted
    </Directory>

    ProxyPass "/api" "http://192.168.100.80:5641"
    ProxyPassReverse "/api" "http://192.168.100.80:5641"
    SSLCertificateFile /etc/letsencrypt/live/bpsapi.rajtech.me/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/bpsapi.rajtech.me/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

```
  1. Remember to point the ProxyPass and ProxyPassReverse to your API's correct node and port. Also make sure to change the Alias to your correct volume.

  2. Find the Pterodactyl absolute path of the API's PNG output folder and put it in the Alias and Directory tags.

  3. Install Let's Encrypt on your Ubuntu Server 20.04

    $ sudo apt install certbot python3-certbot-apache
  4. Run the following command to get a certificate for your domain.

    $ sudo certbot -d example.com --manual --preferred-challenges dns certonly
  5. You will have to add a TXT record to your domain's DNS records. You can find the record in the output of the command.

  6. After adding the record, press enter to continue.

  7. After the certificate is issued, you can remove the TXT record from your DNS records.

  8. Now, You may restart Apache2 to apply the changes.

    $ sudo systemctl restart apache2
  9. You're done! You can now access the API at https://example.com/api


Thanks for reading!