Apache .htaccess syntax to nginx - Simple convert question

Hi,

I have a folder which is /generator/data … The data folder has 777 permissions and inside the data folder i have a .htaccess file with thw following syntax:

order deny,allow

deny from all
 <files ~="" "\.(txt|html|gz)$"="">allow from all</files> 

This .htaccess rule blocks access to the /generator/data for everyone EXCEPT for files with extensions .txt , .html , .gz ….

The problem is i am using NGINX as my Webserver and not Apache. I know that i have to update somehow my Virtual Host file for my domain. Can someone help me to convert this simple Apache rule into NGINX syntax???

Thanks in advance

George

3 Replies

You will have to place location directives into your server section. Something like:

location ~* ^/generator/data/(.*)\.(txt|html|gz)$ {
  allow all;
}
location /generator/data {
  deny all;
}

The ordering of location directives is important, you can read about this here

@melon:

The ordering of location directives is important, you can read about this here

Thank you very much for your help. What do you mean with "The ordering of location directives is important"???

Thanks

George

follow the link melon posted..

To summarize, the order in which directives are checked is as follows:

Directives with the "=" prefix that match the query exactly. If found, searching stops.

All remaining directives with conventional strings. If this match used the "^~" prefix, searching stops.

Regular expressions, in the order they are defined in the configuration file.

If #3 yielded a match, that result is used. Otherwise, the match from #2 is used.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct