Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no "ssl_certificate" is defined for the "listen ... ssl" directive

I am trying to configure nginx server for my website. I am using the following code to configure my server. It works if I add default_server for my www.fastenglishacademy.fr (443) server block.

But in that case, All my subdomains also brings the content of www.fastenglishacademy.fr

And if I remove the default_server, I get the following error:

nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/sites-enabled/fastenglishacademy.fr.conf:14
nginx: configuration file /etc/nginx/nginx.conf test failed

My nginx configuration codes:

server {
        listen 80;
        listen [::]:80;
        server_name fastenglishacademy.fr;
        return 301 https://www.fastenglishacademy.fr$request_uri;
}
server {
        listen 80;
        listen [::]:80;
        server_name www.fastenglishacademy.fr;
        return 301 https://www.fastenglishacademy.fr$request_uri;
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name fastenglishacademy.fr;
        return 301 https://www.fastenglishacademy.fr$request_uri;
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        root /media/fea/www/fastenglishacademy.com;
        index index.html index.htm index.nginx-debian.html;
        server_name www.fastenglishacademy.fr;
        location / {
            etag on;
            try_files $uri$args $uri$args/ /index.html;
        }

        location ~* \.(jpg|jpeg|png|gif|ico|ttf|woff2|woff|svg)$ {
                expires 365d;
        }
        location ~* \.(css|js)$ {
                expires 30d;
        }

        location ~*  \.(pdf)$ {
                expires 15d;
        }
        #WARNING: Please read before adding the lines below!
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;

        # SSL Certificates
        ssl_certificate /path/to/fullchain.pem;
        ssl_certificate_key /path/to/privkey.pem;
        ssl_trusted_certificate /path/to/chain.pem;
}

My links:

https://www.fastenglishacademy.fr/

https://api.fastenglishacademy.fr/

like image 945
Ahsan Aasim Avatar asked Jun 19 '19 13:06

Ahsan Aasim


People also ask

How do I enable https in nginx?

Setting up an HTTPS Server. To set up an HTTPS server, in your nginx. conf file include the ssl parameter to the listen directive in the server block, then specify the locations of the server certificate and private key files: server { listen 443 ssl; server_name www.example.com; ssl_certificate www.

What is SSL certificate for website?

SSL certificates are what enable websites to move from HTTP to HTTPS, which is more secure. An SSL certificate is a data file hosted in a website's origin server. SSL certificates make SSL/TLS encryption possible, and they contain the website's public key and the website's identity, along with related information.

How do I create a https certificate?

To obtain an HTTPS certificate, perform the following steps: Create a private and public key pair, and prepare a Certificate Signing Request (CSR), including information about the organization and the public key. Contact a certification authority and request an HTTPS certificate, based on the CSR.


1 Answers

Your server section is missing ssl_certificate and ssl_certificate_key declarations.

You need to have a .crt and a .key file to run with ssl.

It should looks like

server {

  listen 80;

  listen 443 default_server ssl;
  ssl_certificate /etc/nginx/certs/default.crt;
  ssl_certificate_key /etc/nginx/certs/default.key;

  ... other declarations

}
like image 115
Tiago Gouvêa Avatar answered Oct 20 '22 18:10

Tiago Gouvêa