<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>I misread what you were trying to achieve thanks to no coffee
this morning.</p>
<p>> I do not want to include my file into any server directive.<br>
</p>
<p>You have **no choice** but to specifically include your location
snippets where you want them. Location blocks can't be applied
'globally' unless you have it in the proper server blocks, so you
are kind of wanting two separate disparate things you can't do.</p>
<p>If you don't want to include your location snippets in server
blocks then you need to hardcode the location snippets in the
server blocks themselves. There's not much you can do for this in
that case.</p>
<p><br>
</p>
<p>Thomas<br>
</p>
<div class="moz-cite-prefix">On 6/9/20 11:47 AM, basti wrote:<br>
</div>
<blockquote type="cite"
cite="mid:b338a8d3-025c-3857-7771-8b44a3970cf4@unix-solution.de">
<pre class="moz-quote-pre" wrap="">Does not work.
cat /etc/nginx/conf.d/git.conf
## Disable .htaccess and other hidden files
server {
listen 80 default_server;
server_name _;
location ~ /\.git {
return 404;
}
location ~ /\.(?!well-known).* {
deny all;
access_log off;
log_not_found off;
}
}
Result is, that <a class="moz-txt-link-freetext" href="http://example.com/test/.git/config">http://example.com/test/.git/config</a> is accessible.
On 09.06.20 17:16, Thomas Ward wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">server {
listen 80 default_server;
server_name _;
...
}
The above should do what you're after. Specifies a default-server
listener on port 80 and it matches that special catch-all that accepts
all server_name results. (though, default_server will match anything
that doesn't match any other server_name Host so...)
Thomas
On 6/9/20 11:14 AM, basti wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">Hello,
i want to setup a location match for any hostname/servername like in apache:
cat /etc/apache2/conf-enabled/git.conf
RedirectMatch 404 /\.git
In nginx I try
cat /etc/nginx/conf.d/git.conf
server {
## Disable .htaccess and other hidden files
location ~ /\.(?!well-known).* {
deny all;
access_log off;
log_not_found off;
}
}
But this does not match.
When I remove server {} i get nginx: [emerg] "location" directive is not
allowed here in /etc/nginx/conf.d/git.conf:2
I do not want to include my file into any server directive. It is asking
for trouble, how fast can you forget to add this?
best regards
_______________________________________________
nginx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:nginx@nginx.org">nginx@nginx.org</a>
<a class="moz-txt-link-freetext" href="http://mailman.nginx.org/mailman/listinfo/nginx">http://mailman.nginx.org/mailman/listinfo/nginx</a>
</pre>
</blockquote>
</blockquote>
<pre class="moz-quote-pre" wrap="">_______________________________________________
nginx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:nginx@nginx.org">nginx@nginx.org</a>
<a class="moz-txt-link-freetext" href="http://mailman.nginx.org/mailman/listinfo/nginx">http://mailman.nginx.org/mailman/listinfo/nginx</a></pre>
</blockquote>
</body>
</html>