Nginx rewrite rule that includes a blank spce with Plus Sign

Saturday, April 28, 2018

Nginx rewrite rule that includes a blank spce with Plus Sign :-

f you would like to remove spaces from a URL and then redirect to the stripped URL without the spaces simply use the following to catch all URLs with the issue:

rewrite ^(.*)(\s|%20)(.*)$ $1$3 permanent; # to redirect permanent
rewrite ^(.*)(\s|%20)(.*)$ $1$3 break; # to without redirect

This is basically grabbing everything before the first occurrence of a space \s or a URL encoded space %20 in capture group 1 ($1). The spaces are then captured in group 2 ($2). Then finally anything left over past group 2 is captured in group 3 ($3). I then join capture groups 1 and 3 together ($1$3) to form the redirect URL without the spaces in capture group 2 ($2).

This will work with a URL with multiple spaces throughout the URL, but it is working one at a time. So the URL with 2 spaces in it, will then redirect to the URL with 1 space and then finally to URL with no spaces.

You can of course change the redirect type from permanent if you wish. This will currently redirect with a 301 code.

to replace 2, 3, 4 spaces use below rewrite rule. but this is not recommended. 

rewrite ^(.*)(\s|%20)(.*)(\s|%20)(.*)$ $1$3&5 break;
rewrite ^(.*)(\s|%20)(.*)(\s|%20)(.*)(\s|%20)(.*)$ $1$3$5$7 break;
rewrite ^(.*)(\s|%20)(.*)(\s|%20)(.*)(\s|%20)(.*)(\s|%20)(.*)$ $1$3$5$7$9 break;

Read more...

How To Install Node.js on a CentOS 7 server with all versions :-

How To Install Node.js on a CentOS 7 server with all versions :-

There are lot of ways to install Node.js on a CentOS 7 server, few are mention here, you should use the EPEL installation instructions or the NVM installation steps :-

Install Node from Source :-

First way of acquiring Node.js is to obtain the source code and compile it by ourself.
Step 1:- download the tar file using wget command
             wget http://nodejs.org/dist/v0.10.30/node-v0.10.30.tar.gz

Step 2:- Extract the archive and move into the new directory by typing:
             tar xzvf node-v* && cd node-v*

Step 3:- There are few packages that we need to download from the CentOS repositories in order to compile the code. 
             sudo yum install gcc gcc-c++

Step 4:- Now, we can configure and compile the software:
            ./configure
             make

Step 5:- you can install the software onto your system by typing:
             sudo make install

Step 6:- To check that the installation was successful, check Node version number:
             node --version
            v0.10.30

If you see the version number, then the installation was completed successfully.

Install a Package from the Node Site :-

 Second option for installing Node.js on your server is to get the pre-built packages from the Node.js website and install them.

Step 1:- On your server, change to your home directory and use the wget utility to download the files. Paste the URL you just copied as the argument for the command:

cd ~
wget http://nodejs.org/dist/v0.10.30/node-v0.10.30-linux-x64.tar.gz

Step 2:- using tar command 
        sudo tar --strip-components 1 -xzvf node-v* -C /usr/local

This will install all of the components within the /usr/local branch of your system.

Step 3:- To check that the installation was successful, check Node version number:
          node --version
          v0.10.30

The installation was successful and you can now begin using Node.js on your CentOS 7 server.

Install Node from the EPEL Repository:-

Third way to install nodejs using the EPEL (Extra Packages for Enterprise Linux) repository that is available for CentOS and related distributions.

Step 1:- install epel-release.
            sudo yum install epel-release

Step 2:- Now that you have access to the EPEL repository, you can install Node.js using your regular yum commands:
            sudo yum install nodejs

Step 3:- To check that the installation was successful, check Node version number:
          node --version
          v0.10.30

Many people will also want access to npm to manage their Node packages. You can also get this from EPEL by typing:

          sudo yum install npm


Install Node Using the Node Version Manager (NVM) :-

This is best way of installing Node.js any version that is particularly flexible is through NVM, the Node version manager. 

Step 1:- To install NVM on your CentOS 7 machine, visit the project's GitHub page. Copy the curl or wget command from the README file that displays on the main page. This will point you towards the most recent version of the installation script.

Before piping the command through to bash, it is always a good idea to audit the script to make sure it isn't doing anything you don't agree with. You can do that by removing the | bash segment at the end of the curl command:

curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh

Step 2:- Take a look and make sure you are comfortable with the changes it is making. When you are satisfied, run the command again with | bash appended at the end. The URL you use will change depending on the latest version of NVM, but as of right now, the script can be downloaded and executed by typing:

curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash

Step 3:- This will install the nvm script to your user account. To use it, you must first source your .bash_profile:

source ~/.bash_profile

Step 4:- Now, you can ask NVM which versions of Node it knows about:
             nvm list-remote
. . .
v0.10.29
v0.10.30
 v0.11.0
 v0.11.1
 v0.11.2
 v0.11.3
 v0.11.4
 v0.11.5
 v0.11.6
 v0.11.7
 v0.11.8
 v0.11.9
v0.11.10
v0.11.11
v0.11.12
v0.11.13

Step 5:- You can install a version of Node by typing any of the releases you see. For instance, to get version 0.10.30, you can type:
             nvm install v0.10.30

Step 6:- You can see the different versions you have installed by typing:
             nvm list
        ->  v0.10.30
             system

Step 7:- You can switch between them by typing:
           nvm use v0.10.30
          Now using node v0.10.30

Step 8:- To set this version as the default, type:
          nvm alias default v0.10.30
         default -> v0.10.30

Step 9: -You can verify that the install was successful using the same technique from the other sections, by typing:
            node --version
            v0.10.30
From the version number output, we can tell that Node is installed on our machine as we expected

































Read more...

Nginx - 400 Bad Request – Request Header Or Cookie Too Large

Nginx - 400 Bad Request – Request Header Or Cookie Too Large :-

How to solve "400 Bad Request – Request Header Or Cookie Too Large" issue in Nginx ?

 To Solve "400 Bad Request – Request Header Or Cookie Too Large" issue

 It’s browser error because restart your browser fixes this issue. If you face this error screen too frequently, your Nginx configuration has problem.

How to fix it

Try increasing the large_client_header_buffers directive in nginx

server {
...
  large_client_header_buffers 4 16k;
... 
}


Read more...

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP