Skip to content

Instantly share code, notes, and snippets.

@centminmod
Last active June 2, 2022 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save centminmod/8109281b8222400bbacd8804cc020e9c to your computer and use it in GitHub Desktop.
Save centminmod/8109281b8222400bbacd8804cc020e9c to your computer and use it in GitHub Desktop.
centminmod /usr/local/nginx/conf/staticfiles.conf non-capture mark regex switch

instructions

switch to non-capturing mark regex for /usr/local/nginx/conf/staticfiles.conf

# backup
cp -a /usr/local/nginx/conf/staticfiles.conf /usr/local/nginx/conf/staticfiles.conf-b4-noncapture-mark
# check before
grep location /usr/local/nginx/conf/staticfiles.conf | grep '\.('
# check switch
sed -e 's|\.(|\.(?:|g' /usr/local/nginx/conf/staticfiles.conf | grep '\.('
# switch
sed -i 's|\.(|\.(?:|g' /usr/local/nginx/conf/staticfiles.conf
# check nginx config
nginx -t
# restart nginx server
ngxrestart

examples

grep location /usr/local/nginx/conf/staticfiles.conf | grep '\.('

location ~* \.(gif|jpg|jpeg|png|ico)$ {
    location ~* \.(3gp|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|test|bin)$ {
    location ~* \.(js)$ {
    location ~* \.(css)$ {
  #  location ~* \.(html|htm|txt)$ {
    location ~* \.(eot|svg|ttf|woff|woff2)$ {
sed -e 's|\.(|\.(?:|g' /usr/local/nginx/conf/staticfiles.conf | grep '\.('

    location ~* \.(?:gif|jpg|jpeg|png|ico)$ {
    location ~* \.(?:3gp|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|test|bin)$ {
    location ~* \.(?:js)$ {
    location ~* \.(?:css)$ {
  #  location ~* \.(?:html|htm|txt)$ {
    location ~* \.(?:eot|svg|ttf|woff|woff2)$ {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment