I have here an nginx config. I need to comment out blocks in it:

...things I want...
...things I don't want...
...things I want...

The things are 30-50 lines long, and I won't backup and delete them. I also don't want write #s to the beginning of 30-50 code lines, and I also don't want to script/configure my text editor to do this. I think it is a quite trivial feature.

I tried

...things I want...
...things I don't want...
...things I want...

But it doesn't work. Is it really an unsupported feature in the nginx?

  • Modern editors won't need to be configured. Highlight the rows and run the comment command (e.g. ctrl + / in Atom and VSCode). For Vim, you'll need to configure it, e.g. can install the vim-commentary plugin.
    – Dennis
    Commented Mar 27, 2018 at 10:06
  • 3
    @Dennis In my opinion, to install complex development environments on remote servers, and to run them as root, just for this would be an unfeasible solution for this problem.
    – peterh
    Commented Aug 9, 2018 at 15:27
  • This is my first golden badge for a question score. I am so happy! :-)
    – peterh
    Commented Dec 15, 2021 at 20:48
  • 1
    @Dennis @peterh vim-commentary is not necessary in this case: visual block insert will insert a char at the start of the block for every line. So make a block selection consisting of the first char of the line for every line you want to comment, then do I#<esc>. It's like magic. Check :h v_b_i in vim for more details.
    – Dan Locks
    Commented Aug 23, 2022 at 16:37
  • @peterh You don't need to install complex development environments on remote servers while root, that type of situation is unsafe and should be avoided in the first place. Development environments are a thing. If you must do it live, backup the file as dr__ suggests and use Dan's suggestion of visual block insert in Vim.
    – Dennis
    Commented Jan 25, 2023 at 22:10

1 Answer 1


Nginx configuration files do not support comment blocks; they only accept # at the beginning of a line for a comment. You can also have a valid statement followed by a # and then a comment on the same line. (Source.)

If you have between 30 and 50 lines to ditch out I'd suggest, to avoid confusion, to remove the block entirely (after making a copy of the file, unless you're using a version control system such as Git).

  • Today I happen to use ansible to deploy configs and it has a templating engine supporting long comment blocks. Nginx does not need to see them, it can only see the processed configuration.
    – peterh
    Commented Aug 6, 2023 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .