Nginx - Enable only SSL if Exist SSL Certificates

I have a problem when I create a nginx reverse proxy to redirect to multiple microservices at different URLs.

The system is completely docker-based, and as a result, the same environment is used for development and production. This caused a problem for me when installing SSL, since SSL certificates will only be available in production, so when I configure NGINX with SSL, the development environment no longer works, since there are no ssl certificates.

Here is the relevant part of my conf file -

server {
 listen 80;
 listen 443 default_server ssl;

 server_name          atvcap.server.com;
 ssl_certificate      /etc/nginx/certs/atvcap_cabundle.crt;
 ssl_certificate_key  /etc/nginx/certs/atvcap.key;
 ...
}

But this causes the following when starting my application in development mode -

nginx: [emerg] BIO_new_file ( "/etc/nginx/certs/atvcap_cabundle.crt" ) (SSL: : 02001002: : fopen: : fopen ('/etc/nginx/certs/atvcap_cabundle.crt ',' r '): 2006D080: BIO-: BIO_new_file: )

SSL, "/etc/nginx/certs/atvcap_cabundle.crt"?

- -

if (-f /etc/nginx/certs/atvcap_cabundle.crt) {
  ssl_certificate      /etc/nginx/certs/atvcap_cabundle.crt;
  ssl_certificate_key  /etc/nginx/certs/atvcap.key;
}

:

nginx: [emerg] "ssl_certificate" /etc/nginx/conf.d/default.conf:7

- , - ?

+4

Source: https://habr.com/ru/post/1690067/


All Articles