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...

mobile version detect with same url in nginx using proxy_pass :-

Friday, March 30, 2018

Mobile version detect with same url in nginx using proxy_pass :-

if ($http_user_agent ~* "/Mobile|Android|BlackBerry/") {
    proxy_pass    http://m.example.com$request_uri;
}

proxy_pass    http://www.example.com$request_uri;


http {
    upstream app-pc {
        server 127.0.0.1:8001;
    }

    upstream app-mobile {
        server 127.0.0.1:8002;
    }

    server {
        listen       8080;
        server_name  localhost;

        # check user agent
        if ($http_user_agent ~* '(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)') {
          set $ua_type "@mobile";
        }

        location / {
            # root
            if ($ua_type = "@mobile"){
                set $page_cache_path /var/www/app_pc/public;
            }
            if ($ua_type != "@mobile"){
                set $page_cache_path /var/www/app_mobile/public;
            }
            root $page_cache_path;

            # for page cache
            if (-f $request_filename) { 
                break; 
            }
            if (-f $request_filename/index.html) {
                rewrite (.*) $1/index.html break;
            }
            if (-f $request_filename.html) {
                rewrite (.*) $1.html break;
            }

            # proxy
            if ($ua_type = "@mobile"){
                proxy_pass http://app-mobile;
            }
            if ($ua_type != "@mobile"){
                proxy_pass http://app-pc;
            }
        }
    }
}

Read more...

How to connect multiple VPNs using OpenVPN on Windows 7 on the same time

How to connect multiple VPNs using OpenVPN on Windows 7 on the same time :-

you will need to create some additional TAP-WIN32 adapters if you haven't already.

If you are using OpenVPN 2.3.x or later, run addtap.bat:

C:\Program Files\TAP-Windows\bin\addtap.bat
If you are using an older version of OpenVPN, run the tapinstall command

C:\Program Files\OpenVPN\bin\tapinstall.exe
C:\Program Files (x86)\OpenVPN\bin\tapinstall.exe
(NOTE: Maybe you should open the cmd with Administrator Privileges)

The easiest way, not to mention tapinstall.exe, is to run Start > All Programs > OpenVPN > Utilities > Install > Add a new TAP vitrual ethernet adapter

Please remember to run it with administrator privileges, in other case you will just get tapinstall failed.

Read more...

Unable to send an email: 535 5.7.8 Error: authentication failed: authentication failure

Thursday, March 29, 2018

Unable to send an email: 535 5.7.8 Error: authentication failed: authentication failure:-


we can be found this exception in /var/log/maillog :

Dec  4 06:06:34 servername postfix/qmgr[6334]: DA7FB101118C: from=, size=827, nrcpt=1 (queue active)
Dec  3 04:04:22 servername postfix/error[25863]: DA7FB101118C: to=, relay=none, delay=0.1, delays=0.1/0/0/0, dsn=4.7.8, status=deferred (delivery temporarily suspended: SASL authentication failed; server someexternalserver.com [203.0.113.2] said: 535 5.7.8 Error: authentication failed: authentication failure)
relayhost is configured in /etc/postfix/main.cf :

# cat /etc/postfix/main.cf | grep  "relayhost ="
relayhost = someexternalserver.com

Cause
Issues on someexternalserver.com side.

Resolution
Contact owner of someexternalserver.com to check the issue.
2.1. relayhost can be disabled by commenting it in /etc/postfix/main.cf

    # cat /etc/postfix/main.cf | grep  "relayhost ="
    #relayhost = someexternalserver.com
2.2. Restart postfix:

    # service postfix restart

Read more...

How to remove files /bin/rm: Argument list too long

How to remove files /bin/rm: Argument list too long :-

How to remove files /bin/rm: Argument list too long by using below command.

find . -mindepth 1 -iname "*.xls" -print0|xargs --no-run-if-empty --null rm -rf

Read more...

How to Flush or Delete Postfix Mail Queue

How to Flush or Delete Postfix Mail Queue:-

there are following commands to flush/delete postfix mail queue.

1. List All Emails :-
To list all mail of queue, use one of the following commands.
postqueue -p

2. Flush All Emails :-
To delete or flush all emails from Postfix mail queue using the following command.
postsuper -d ALL

3. Flush Deferred Mails Only :-
You can only delete all deferred emails only from mail queue. Use the following command to delete deferred emails from the queue.
postsuper -d ALL deferred

4. Remove Specific Email :-
If you want to remove any specific email. Use the following command to remove specific emails only. First search the ID of that email like below command
postqueue -p | grep "email@example.com"

056CB129FF0*    5513 Sun Feb 26 02:26:27  email@example.com
Now delete the mail from mail queue with id 056CB129FF0.

postsuper -d 056CB129FF0

Read more...

How to Install Apache Solr 5.1 on CentOS 6

How to Install Apache Solr 5.1 on CentOS 6 :-

following are the steps for how to install Apache Solr 5.1 on a CentOS 6 server . 

Step 1. Install Solr :-
download and install solr first.
# cd /opt/solr 
# wget http://mirror.symnds.com/software/Apache/lucene/solr/5.1.0/solr-5.1.0.tgz -O solr-5.1.0.tgz

Uncompress the file:
# tar -xzvf ./solr-5.1.0.tgz
Now the directory /opt/solr/solr-5.1.0 will contain all the Solr files. 

Step 2. Install Java :-
First, check if Java is already installed:
# which java
  If not installed, install the latest version :

# yum list available java* 
# yum install java-1.8.0-openjdk.x86_64

Verify install:
# which java 
[...] 
# java -version 
openjdk version "1.8.0_45" 
OpenJDK Runtime Environment (build 1.8.0_45-b13) 
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)

Step 3. Start Solr :-
Next start Solr and test instance:
# cd /opt/solr/solr-5.1.0 
# bin/solr start -noprompt

Verify Solr is running:
# ps aux | grep solr 
[...] 
# lsof -i :8983 
[...]

Step 4. Install NMAP :-
The Solr service can also be verified from a remote machine. First, install nmap if not already installed on remote machine:
# yum install nmap
Then test the Solr service from the remote machine:
# nmap -p 8983 [remote IP address] 

Starting Nmap 5.51 ( http://nmap.org ) at * EDT 
Nmap scan report for 
Host is up (0.054s latency). 
PORT STATE SERVICE 
8983/tcp open unknown 

Nmap done: 1 IP address (1 host up) scanned in 0.25 seconds

If the remote machine is unable to connect try setting up firewall rules, or disable firewall for testing:
# service iptables stop
Stopping Solr can be accomplished using:
# cd /opt/solr/solr-5.1.0 
# bin/solr stop


Step 5. Auto Start Solr :-
Finally, Solr can be setup as a service that starts when the server boots. Create the script file 

/etc/init.d/solr and add:

#!/bin/sh 
# chkconfig: 2345 95 20 
# description: Solr Server 
# Solr Server service start, stop, restart 
# @author Shay Anderson 04.15 

SOLR_DIR="/opt/solr/solr-5.1.0" 

case $1 in 
      start) 
            echo "Starting Solr..." 
            $SOLR_DIR/bin/solr start -noprompt 
            sleep 1 
            lsof -i :8983 
            ;; 
      stop) 
            echo "Stopping Solr..." 
            $SOLR_DIR/bin/solr stop 
            ;; 
      restart) 
            $0 stop 
            sleep 2 
            $0 start 
            ;; 
      status) 
            $SOLR_DIR/bin/solr status 
            ;; 
      *) 
            echo "Usage: $0 [start|stop|restart]" 
            exit 1 
            ;; 
esac 

exit 0

Save the file and set permissions:
# chmod +x /etc/init.d/solr

Now the Solr service can be started/stopped using:
# service solr start 
[...] 
# service solr stop 
[...]

Enable auto start service on server boot:
# cd /etc/init.d 
# chkconfig --add solr 
# chkconfig | grep solr
Now the Solr service will start on server boot. 

Create New Core
A new core can be created using:
# cd /opt/solr/solr-5.1.0 
# bin/solr create -c mycore
This will create the core and core directory /opt/solr/solr-5.1.0/server/solr/mycore

Read more...

How to Show All Running Processes in Linux

How to Show All Running Processes in Linux :-

How to show all running process in Linux operating systems using command line or GUI options.

Linux commands to list processes :-
following commands to display info about processes on Linux:

top command : Display and update sorted information about processes.
atop command : Advanced System & Process Monitor.
htop command : Interactive process viewer.
pgrep command : Look up or signal processes based on name and other attributes.
pstree command : Display a tree of processes.

How to list process with the ps command :-
following ps command to display all running process:
# ps -aux | less

OR
# ps aux | less

Where,

A : Select all processes
u : Select all processes on a terminal, including those of other users
x : Select processes without controlling ttys

How To See every process on the Linux system :-
Either pass -A or -e option to show all processes on your server/workstation powered by Linux:
# ps -A
# ps -e

How to see every process except those running as root :-
To negates the selection pass the -N or --deselect option to the ps command:
# ps -U root -u root -N

OR
# ps -U root -u root --deselect

How to See process run by user xyz :-
Select by process by effective user ID (EUID) or name by passing username such as xyz:
# ps -u xyz

Linux running processes with top command :-
The top program provides a dynamic real-time view of a running system. Type the top at command prompt:
# top


How to display a tree of processes :-
The pstree command shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.
$ pstree

Print a process tree using ps :-
# ps -ejH
# ps axjf

How to Get info about threads using following command :-
Type the following command:
# ps -eLf
# ps axms

How to show Task: Get security info :-
Type the following command:
# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

How to save process snapshot to a file :-
Type the following command:
# top -b -n1 > /tmp/process.log

Or you can email result to yourself : -
# top -b -n1 | mail -s 'Process snapshot' you@example.com

How to lookup process by name :-
Use pgrep command command. It looks through the currently running processes and lists the process IDs which matches the selection criteria to screen. For example, display firefox process id:
$ pgrep firefox

Sample outputs:

3356

Following command will list the process called sshd which is owned by a user called root:
$ pgrep -u root sshd

Read more...

How to Check Postfix Version

How to Check Postfix Version :-

How to check your postfix mail server version. Basically, postfix is a open-source mail transfer agent (MTA) and an alternative for Sendmail service which provide the same function.

Following Command for check version  :

postconf -d | grep mail_version

Examples :

[root@centos ~]# postconf -d | grep mail_version
mail_version = 2.6.2
milter_macro_v = $mail_name $mail_version

Read more...

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP