Posts

Showing posts with the label Apache

https://www.vultr.com

The Everywhere Cloud

Deploy an instance.
Accelerate your application.


Redirect Apache HTTP to HTTPS in FreeBSD

Image
After enabling HTTPS on the web server in FreeBSD, remote users can be redirected to this secure protocol by automatically rewriting the URL. ========== 1. Log in to "root". Regular users must be part of the "wheel" group in order to do this. user@host: $ su - 2. Open the Apache main configuration file. root@host: # ee /usr/local/etc/apache24/httpd.conf 3. Find and uncomment the following Apache directives. # BEGIN CODE # ... LoadModule rewrite_module libexec/apache24/mod_rewrite.so # Apache rewrite engine Include etc/apache24/Includes/*.conf # Custom configuration files # ... # END CODE 4. Create a custom config file in the "Includes" directory. root@host: # ee /usr/local/etc/apache24/Includes/myrewrite.conf 5. Place the following code in the custom config file. # BEGIN CODE # ... RewriteEngine On # Enables directives for rewriting. RewriteCond %{HTTPS} !=on # Verifies that the connection is not yet in HTTPS. RewriteRule ^/?(.*) https://%{SERVER_NAME}/$...

Enable Apache HTTPS in FreeBSD

Image
The following procedure activates HTTPS for the Apache web server in FreeBSD. This secure protocol uses TLS/SSL certificates to encrypt the data transferred between the remote user and the web server. Sensitive information is protected from being captured by malicious actors using sniffing tools along the network route. ========== 1. PREREQUISITES 1.1. Make a self-signed SSL certificate. [  Details  ] 2. ACTIVATION 2.1. Log in to "root". Regular users must be part of the "wheel" group in order to do this. user@host: $ su - 2.2. Open the Apache main configuration file. root@host: # ee /usr/local/etc/apache24/httpd.conf 2.3. Find and uncomment the following Apache directives. # BEGIN CODE # ... LoadModule socache_shmcb_module libexec/apache24/mod_socache_shmcb.so # Needed by the "SSLSessionCache" directive in httpd-ssl.conf # ... LoadModule ssl_module libexec/apache24/mod_ssl.so # Needed by the "SSLCipherSuite" directive in httpd-ssl.conf # ... ...

Self-Signed Certs for Apache in FreeBSD

Image
The following procedure shows how to apply self-signed certificates to the Apache web server in FreeBSD. After  creating and installing the TLS/SSL certificate/key pair, they can be utilized to secure FreeBSD web services with encryption during the development and testing process. It is important to keep in mind that self-signing may be deemed UNTRUSTWORTHY in a production environment. ========== 1. Log in to "root". Regular users must be part of the "wheel" group in order to do this. user@host: $ su - 2. Go to the directory containing the Apache site configuration files. root@host: # cd /usr/local/etc/apache24/extra 3. BACK UP the default HTTPS configuration file for the secure site. root@host: # cp httpd-ssl.conf httpd-ssl-conf.back 4. Open the default HTTPS configuration file. root@host: # ee httpd-ssl.conf 5. Find and modify the following Apache directives. # BEGIN CODE # ... SSLCertificateFile "/usr/local/etc/apache24/server.crt" # The self-signe...

Disable Web Server Signatures in FreeBSD

Image
Hide server details from potential online threats in a few easy steps. ========== 1. Log in to "root". Regular users must be part of the "wheel" group in order to do this. user@host: $ su - 2. Open the Apache main configuration file. root@host: # ee /usr/local/etc/apache24/httpd.conf 3. Find and uncomment the following Apache directive. # BEGIN CODE # ... Include etc/apache24/extra/httpd-default.conf # Default config for the Apache web server. # ... # END CODE 4. Open the Apache default settings configuration file. root@host: # ee /usr/local/etc/apache24/extra/httpd-default.conf 5. Find and modify the following Apache directives. # BEGIN CODE # ... ServerTokens Prod # "Prod" reduces Apache info sent by the server in its HTTP response header. # ... ServerSignature Off # "Off" removes info on server, host, and port from error pages and other auto-generated docs. # ... # END CODE 6. Open the PHP configuration file. root@host: # ee /usr/local/etc/ph...

Owner and Perm of Web Items in FreeBSD

Image
The following steps provide all directories and files in the "data" folder with the appropriate ownership and permissions to ensure smooth operation of the web server. This also prevents unauthorized users from viewing and modifying them. ========== 1. Log in to "root". Regular users must be part of the "wheel" group in order to do this. user@host: $ su - 2. Change ownership of all items to user "root" and group "www". root@host: # chown -R root:www /usr/local/www/apache24/data 3. Change permission modes to 750 for directories only. User "root" can (r)ead, (w)rite, and e(x)ecute directories. Users included in the group "www" can (r)ead and e(x)ecute but NOT write to directories. All other users are excluded. root@host: # find /usr/local/www/apache24/data -type d -exec chmod 750 {} + 4. Change permission modes to 640 for files only. User "root" can (r)ead and (w)rite but NOT execute files. Users included i...

Self-Signed Certs for Apache in Debian-based Linux

Image
The following procedure shows how to apply self-signed certificates to the Apache web server in Debian-based Linux distributions. After creating and installing  the TLS/SSL certificate/key pair, they can be utilized to  secure Debian-based Linux web services  with encryption during the development and testing process. It is important to keep in mind that self-signing may be deemed UNTRUSTWORTHY in a production environment. ========== 1. Go to the directory containing the Apache site configuration files. user@host: $ cd /etc/apache2/sites-available 2.  BACK UP the default HTTPS configuration file for the secure site. user@host: $ sudo cp default-ssl.conf default-ssl-conf.back 3. Open the default HTTPS configuration file. user@host: $ sudo nano default-ssl.conf 4. Find and modify the following Apache directives. # BEGIN CODE # ... SSLCertificateFile /etc/ssl/certs/myserver.crt # The self-signed certificate. SSLCertificateKeyFile /...

Enabling .htaccess in Apache for Drupal

Image
Content management systems like Drupal require specific web server directives in order to work properly. The following steps enable Apache to recognize .htaccess files containing those specific web server directives. The steps outlined here require the use HTTPS for better security on both Debian-based Linux distributions and the FreeBSD operating system . ========== 1. DEBIAN-BASED LINUX DISTRIBUTIONS 1.1. Go to the directory containing the Apache site configuration files. user@host: $ cd /etc/apache2/sites-available 1.2.  BACK UP the default HTTPS configuration file for the secure site. user@host: $ sudo cp 000-default-ssl.conf 000-default-ssl-conf.back 1.3. Open the default HTTPS configuration file. user@host: $ sudo nano 000-default-ssl.conf 1.4. Find the "DocumentRoot" section and add the "Directory" block marked "For Drupal" as follows. # BEGIN CODE <IfModule mod_ssl.c>         <VirtualHost _default_:443> # .....

Redirect Apache HTTP to HTTPS in Debian-based Linux

Image
Once HTTPS is enabled on the web server, remote users can be redirected to this secure protocol by automatically rewriting the URL. ========== 1. Enable the Rewrite module. user@host: $  sudo a2enmod rewrite 2. Change the current working directory to the Apache site configuration files. user@host: $ cd /etc/apache2/sites-available 3.  BACK UP the default HTTP configuration file for the non-secure site. user@host: $ sudo cp 000-default.conf 000-default-conf.back 4. Open the default HTTP configuration file. user@host: $ sudo nano 000-default.conf 5. Replace all contents in the default HTTP configuration with the following code. # BEGIN CODE RewriteEngine On # Enables directives for rewriting. RewriteCond %{HTTPS} !=on # Verifies that the connection is not yet in HTTPS. RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] # Redirects to the current location but in HTTPS. # END CODE 6. Restart the web serve...

Enable Apache HTTPS in Debian-based Linux

Image
The following procedure activates HTTPS for the Apache web server in Debian-based Linux distributions. This secure protocol uses TLS/SSL certificates to encrypt the data transferred between the remote user and the web server. Sensitive information is protected from being captured by malicious actors using sniffing tools along the network route. ========== 1. Enable the SSL module. user@host: $ sudo a2enmod ssl 2. Enable the default configuration for the secure site. user@host: $ sudo a2ensite default-ssl.conf 3. Restart the web server. user@host: $ sudo /etc/init.d/apache2 restart 4. Test the secure site by accessing localhost with a simple browser. user@host: $ lynx https://localhost ==========

Owner and Perm of Web Items in Debian-based Linux

Image
The following steps provide all directories and files in the www folder with the appropriate ownership and permissions to ensure smooth operation of the web server. This also prevents unauthorized users from viewing and modifying them. ========== 1. Change ownership of all items to user "root" and group "www-data". user@host: $  sudo chown -R root:www-data /var/www 2. Change permission modes to 750 for directories only. User "root" can (r)ead, (w)rite, and e(x)ecute directories. Users included in the group "www-data" can (r)ead and e(x)ecute but NOT write to directories. All other users are excluded. user@host: $  sudo find /var/www -type d -exec chmod 750 {} + 3. Change permission modes to 640 for files only. User "root" can (r)ead and (w)rite but NOT execute files. Users included in the group "www-data" can (r)ead but NEITHER write NOR execute files. All other users are excluded. user@host: $  sudo fi...

Disable Web Server Signatures in Debian-based Linux

Image
Hide server details from potential online threats in a few easy steps. ========== 1. Open the Apache security configuration file. user@host: $ sudo nano /etc/apache2/conf-enabled/security.conf 2. Find and modify the following Apache directives. # BEGIN CODE # ... ServerTokens Prod # "Prod" reduces Apache info sent by the server in its HTTP response header. # ... ServerSignature Off # "Off" removes info on server, host, and port from error pages and other auto-generated docs. # ... # END CODE 3. List the PHP "x.y" versions available and open the configuration file of the appropriate version. user@host: $ ls -lha /etc/php user@host: $ sudo nano /etc/php/x.y/apache2/php.ini 4. Find and modify the following PHP config. ; BEGIN CODE ; ... expose_php = Off ; "Off" removes the PHP signature sent by the server in its HTTP response header. ; More info at https://php.net/expose-php ; ... ; END CODE 5. Restart the ser...