How to set up HTTP-based domain validation on Nginx well-known/pki-validation File configuration
1. Create a directory for storing the validation files. For example, let’s create a directory named ‘prafulbhuskute.com/.well-known/pki-validation/'
within your Nginx web server’s document root directory.
sudo mkdir -p /var/www/html/prafulbhuskute.com/.well-known/pki-validation/
2. Generate the validation file. Depending on the certificate authority (CA) you are using, they may provide you with a specific file or content that needs to be placed in the validation file. Obtain the validation file or content from your CA.
3. Create the validation file within the directory you created earlier. For example, let’s assume the validation file is named ‘file1234.txt’. You can create the file using the following command:
sudo nano /var/www/html/prafulbhuskute.com/.well-known/pki-validation/file1234.txt
4. Paste the content provided by your CA into the validation file and save it.
5. Configure Nginx to serve the validation file. Open the Nginx configuration file for your website. This file is typically located in the ‘/etc/nginx/conf.d/’ directory and has a ‘.conf’ extension.
sudo nano /etc/nginx/conf.d/prafulbhuskute.conf
6. Add a location block within the ‘server’ block to serve the validation files. The configuration should look similar to the following:
server {
# Your existing server configuration
location /.well-known/pki-validation {
alias /var/www/html/prafulbhuskute.com/.well-known/pki-validation;
allow all;
}
# Your existing server configuration
}
or you can try this
server {
listen 80;
listen [::]:80;
root /var/www/html/prafulbhuskute.com;
server_name prafulbhuskute.com www.prafulbhuskute.com;
index index.html index.htm index.nginx-debian.html;
location / {
autoindex on;
}
}
if you get error 404 on nginx server, run following cmd
chmod -R 755 prafulbhuskute.com/
7. Save the configuration file and exit the text editor.
8. Test the Nginx configuration to ensure there are no syntax errors:
sudo nginx -t
9. If the configuration test is successful, reload Nginx to apply the changes:
sudo service nginx reload
10. Verify that the validation file is accessible by visiting ‘https://prafulbhuskute.com/.well-known/pki-validation/file1234.txt’ in a web browser. Ensure that the validation file is served correctly.
Once the validation file is accessible via HTTP, you can proceed with the domain validation process required by your CA.