nginx syntax error - listen directive not allowed


I have been following through a few different articles, but am now getting an error.

"listen" directive not allowed here...

listen [::]:443 ssl; # managed by certbot

After I set up certbot it was fine, so I’m not sure what else I have done to affect it.

The only change I have made to the file is adding WordPress bits as below.

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;


    location / {
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;

Any help is much appreciated.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
January 1, 2021
Accepted Answer

Hi there,

Can you run the following command to test your Nginx config syntax:

sudo nginx -t

And then share the output here.

Also, can you share your whole Nginx server block here as well?

Regards, Bobby

Thanks @bobbyiliev for your assistance.

server {

        root /var/www/;
        index index.html index.htm index.nginx-debian.html;


        location = /favicon.ico { log_not_found off; access_log off;}
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;

        location / {
        #       try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php$is_args$args;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

        location ~ /\.ht {
                deny all;


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

server {
    if ($host = {
        return 301 https://$host$request_uri;
    } # managed by Certbot

total 232K
drwxr-x---  6 general general 4.0K Dec 31 19:11 .
drwxr-xr-x  6 root    root    4.0K Jan  2 14:13 ..
drwxr-x---  2 general general 4.0K Dec 31 18:58 html
-rw-r-----  1 general general  405 Feb  6  2020 index.php
-rw-r-----  1 general general  20K Feb 12  2020 license.txt
-rw-r-----  1 general general 7.2K Jun 26  2020 readme.html
-rw-r-----  1 general general 7.0K Jul 28 17:20 wp-activate.php
drwxr-x---  9 general general 4.0K Dec  8 22:13 wp-admin
-rw-r-----  1 general general  351 Feb  6  2020 wp-blog-header.php
-rw-r-----  1 general general 2.3K Oct  8 21:15 wp-comments-post.php
-rw-r-----  1 general general 3.2K Dec 31 18:30 wp-config.php
-rw-r-----  1 general general 2.9K Feb  6  2020 wp-config-sample.php
drwxr-x---  4 general general 4.0K Dec  8 22:13 wp-content
-rw-r-----  1 general general 3.9K Jul 30 19:14 wp-cron.php
drwxr-x--- 25 general general  12K Dec  8 22:13 wp-includes
-rw-r-----  1 general general 2.5K Feb  6  2020 wp-links-opml.php
-rw-r-----  1 general general 3.3K Feb  6  2020 wp-load.php
-rw-r-----  1 general general  49K Nov  9 10:53 wp-login.php
-rw-r-----  1 general general 8.4K Apr 14  2020 wp-mail.php
-rw-r-----  1 general general  21K Nov 12 14:43 wp-settings.php
-rw-r-----  1 general general  31K Sep 30 21:54 wp-signup.php
-rw-r-----  1 general general 4.7K Oct  8 21:15 wp-trackback.php
-rw-r-----  1 general general 3.2K Jun  8  2020 xmlrpc.php

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel