Configure the Nginx Server
This section covers the following Nginx Server configuration tasks:
- Set Futurex PKCS #11 environment variables
- Configure Nginx certificates.
- Configure Nginx to use the signed certificate and private key stored on the KMES.
The following sections provide detailed instructions.
In a terminal, run the following commands to set the required FXPKCS11 environment variables, modifying the file path to match the location where the libfxpkcs11.so and fxpkcs11.cfg files are located on your system:
Perform the following tasks to configure Nginx certificates:
- Create a key pair on the KMES.
- Generate a CSR.
- Create a self-signed root CA.
- Sign the Nginx Server CSR.
- Create a client certificate.
In a terminal, run the following command to create a new RSA key pair on the KMES by using pkcs11-tool:
When this pkcs11-tool command prompts for the PIN, enter the password of the identity configured in fxpkcs11.cfg.
If successful, the command output lists the keys that pkcs11-tool created on the KMES.
In a terminal, run the following command to generate a CSR from the private key that pkcs11-tool created on the KMES for Nginx in the preceding step. Ensure that the common name of the Nginx Server certificate matches the domain name or IP address of the virtual host for which you are configuring it.
The following instructions show you how to create and use a self-signed root certificate authority (CA) as a demonstration. In a production environment, use a secure certificate authority (such as the KMES Series 3) for all private key generation and certificate signing operations.
In a terminal, run the following commands to generate a root private key and self-signed certificate.
In a terminal, run the following command to issue a signed Nginx Server certificate by using the self-signed root CA created in the preceding section:
In a terminal, generate a client key pair by using the following command:
Run the following command to create a client certificate signing request:
Run the following command to sign the CSR with the CA certificate you created:
Run the following command to convert the signed client certificate to PKCS #12 format for insertion into the browser:
If you encounter SSL errors when connecting to your Nginx server in the web browser after the completion of this guide, ensure that you added the v3_leaf extensions properly. Nginx requires the SANS (added in as IP.1 under the v3_leaf extension in your openssl.cnf file) in both the signed Nginx certificate and the browser client certificate.
This section covers how to modify the configuration file for an Nginx virtual host. Configuration of a virtual host is outside the scope of this guide. Refer to the documentation specific to your operating system if you have not already configured a virtual host.
Before making any changes, stop your Nginx server with the following commands:
In a text editor, open the configuration file in your conf.d folder in the Nginx directory for the virtual host you want to configure HTTPS for and modify it as shown in the following example:
Modify the location of the signed Nginx certificate specified in the ssl_certificate define according to where it is stored on your system.
The object name of the Nginx private key specified in the ssl_certificate_key define must match the label you set in the pkcs11-tool command.
Restart your Nginx server by using the following command:
This integration needs the daemon off startup parameter. Do not close the window during operation. If you get an error message on startup, check to ensure a service is not already running on port 443.
Confirm that Nginx uses the new TLS certificate and private key stored on the KMES for HTTPS connections
The following steps use a Firefox web browser. Using a different browser might require altered actions, but the fundamental steps are the same.
In Firefox, select Settings > Privacy & Security > Certificates > View Certificates.
Select Your Certificates > Import to import the PKCS #12 client certificate (ssl-client-pkcs12.p12).
Select Authorities > Import to import the CA certificate (ssl-ca-cert.pem).
Browse to the IP address of Nginx website that runs over HTTPS. If you configured a client certificate in the browser for mutual authentication, you should see a lock icon next to the web address.
View the certificate that the website served to the browser and confirm that it is the certificate configured in Nginx.