Nginx replace PEM files in configuration

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Nginx replace PEM files in configuration



I'm configuring my Nginx with some provided certificates.



At first, I tried with self signed certificates, and it works.
I just used:


$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048



And editing my self certificates file:


$ sudo nano /etc/nginx/snippets/self-signed.conf

ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;



And including the pem file:


$ /etc/nginx/snippets/ssl-params.conf
ssl_dhparam /etc/ssl/certs/dhparam.pem;



Generating a bak file


$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak



And editing the file: /etc/nginx/sites-available/default


/etc/nginx/sites-available/default



With


server {
listen 80 default_server;
listen [::]:80 default_server;
server_name server_domain_or_IP;
return 302 https://$server_name$request_uri;
}

server {

# SSL configuration

listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
....
}



To test if all is ok, I execute:


sudo nginx -t



Ok, that is working, and display a message:



This connection is not secure



And that is OK, because is a self-signed certificate.



But, at the moment to replace with the valid pem files, my provider sent me 2 files:



yourdomain.app-key.pem and yourdomain.app-cert.pem


yourdomain.app-key.pem


yourdomain.app-cert.pem



I puth them in the right place and update the file with:



$ sudo nano /etc/nginx/snippets/self-signed.conf


ssl_certificate /etc/ssl/certs/yourdomain.app-cert.pem;
ssl_certificate_key /etc/ssl/private/yourdomain.app-key.pem;



To test if all is ok, I execute:


sudo nginx -t

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful



But, when I try to visit the site, still appears my own self-signed certificate.



What step am I losing in the process?




1 Answer
1



When you run sudo nginx -t you're just testing the configuration not applying it. Try to reload the nginx service (the actual command depends on your OS)


sudo nginx -t


$ sudo service nginx reload



or


$ sudo systemctl reload nginx



Then revisit the site, if it still fails, try using private browser mode to verify that it's not some sort of browser caching issue






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Better method to check all objects' parameters with a single call

C++ virtual function: Base class function is called instead of derived