Trinitytuts Tech
5 Followers

Ignore or Exclude specific files or complete folder in NGINX

people

Aneh Thakur

. 1 min read

In this post, I will show you how we can Ignore or exclude specific files or folder from NGINX configuration.

Prerequisites

Before we start updating the configuration file I hope you have good knowledge of the NGINX server because if something goes wrong in the config file your site goes down, and to update configuration file you need complete access of server.

Steps to update the NGINX Configuration file

Step 1. Login to the server via terminal or putty.


Step 2. Go to cd /etc/nginx location and open you site configuration file nano xyz.mysite.com.

Step 3. Open file is open for the edit you can ready to change the setting. Now if you only want to allow specific files to ignore then you can change setting like this.

location / {
	rewrite ^/((?!manifest.json|pwabuildersw.js).*)$ /index.php?slug=$1 last;
}

In my case, I want to ignore the manifest.json file and pwabuildersw.js file so I can update my configuration as shown in the above code.

Step 4. If you want to ignore a specific folder you can do like this.

location /assets {
  # Nothing here
}

In my case, I want to ignore assets folder.

Step 5. If you want to ignore both folder and specific file then you can do like this as shown in the below code.

server {
	listen 80;
	listen [::]:80;

	root /var/www/html/test/sample;

	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name MY_SERVER_ADDRESS;

	location /assets {
        # Nothing here
    }

	location / {
		rewrite ^/((?!manifest.json|pwabuildersw.js).*)$ /index.php?slug=$1 last;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.2-fpm.sock;
	}

	location ~ /\.ht {
		deny all;
	}
}

Step 6. Save your file by pressing ctrl+o and exit ctrl+x.

Step 7. Reload your NGINX configuration sudo systemctl reload nginx.

That’s it now you can check your site. I hope you understand how to Ignore specific files and folders in NGINX server.


More Stories from

Aneh Thakur
Aneh Thakur.2 min read

Monetize react native app with Google Admob

Implement Google Mobile Ads in your React Native application to allows you to monetize your app with AdMob.

.
Monetize react native app with Google Admob
Aneh Thakur
Aneh Thakur.5 min read

Deploying React & Node.js App using GitHub Actions CI/CD

Learn how to deploy React and Node.Js application using CI/CD pipeline with Github Actions.

Deploying React & Node.js App using GitHub Actions CI/CD
Aneh Thakur
Aneh Thakur.1 min read

What is DevOps?

DevOps is a set of practices, tools, and a cultural philosophy that automate and integrate the processes between software development and IT teams. It emphasizes team empowerment, cross-team communication and collaboration, and technology automation.

.
What is DevOps?
Aneh Thakur
Aneh Thakur.2 min read

Different between find(), filter() and map() in javascript

Learn different between find(), filter() and map() in javascript with example and other array methods in javascript.

.
Aneh Thakur
Aneh Thakur.3 min read

All about MongoDB

MongoDB is an open-source document-oriented database that is designed to store a large scale of data and also allows you to work with that data very efficiently. It is categorized under the NoSQL (Not only SQL) database because the storage and retrieval o

.
All about MongoDB