How to Fix nginx: [warn] the “ssl” directive is deprecated, use the “listen … ssl”
When updating nginx to a newer version, you may have error ;
nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/sites-enabled/foobar:49
Nginx uses a YAML-like definition format to create configurations. This format evolves over time by adding, removing, or changing keywords.
This tutorial shows you how to fix nginx’s “ssl” deprecation warning telling you to use “listen … ssl” instead.
Fix “ssl” Directive Is Deprecated, Use “listen … ssl”
The deprecation warning tells you to reconfigure your SSL settings. In nginx 1.10 (and below) you configured SSL using the ssl on;
setting. Here’s how it worked:
server {
listen 443 ssl;
server_name foobar.com;
ssl on; ##this line in not work for newer nginx
}
This setting changed in nginx 1.12 (and above). You now need to configure SSL in the same line as the listen
statement. Also, the ssl on;
setting is no longer available. You can remove it.
Change your nginx configuration to:
server {
listen 443 ssl;
server_name foobar.com;
#ssl on; #comment or remove this line
}
Check your nginx config again to verify that it’s correctly configured:
sudo nginx -t
Finally, you can may reload or restart the nginx service to populate the configuration changes.
sudo service nginx reload
That’s it!