Category Archives: Linux

How to use Nginx as reverse proxy for Node apps?

First we need to do followings
1. Create Node App
2. Create Nginx server block
3. Update hosts file
4. Restart Nginx

1. Create Node App
Already I have node app that is running on http://localhost://3000
So start with second point.
2. Create nginx server block
Run following command on terminal

sudo nano /etc/nginx/sites-available/{app.dev}

And put following contents

server {
    listen 80;

    server_name app.dev;

    location / {
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $http_host; 
        proxy_set_header X-NginX-Proxy true; 

        proxy_pass http://localhost:3000/; 
        proxy_redirect off; 

        # Socket.IO Support 
        proxy_http_version 1.1; 
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade"; 
    }
}

and press control+o and then control+x to save & close file
Now run following command on terminal to create symlink

sudo ln -s /etc/nginx/sites-available/app.dev /etc/nginx/sites-enabled/app.dev 

3. Update hosts file

sudo nano /etc/hosts

put following line at bottom of this file
127.0.0.1 app.dev
and press control+o and then control+x to save & close file
4. Restart Nginx

sudo service nginx restart

Git Ignore File mod changes

I was working with git and facing file mod changes issues every time.
Then i google it and found a way to ignore file mod changes as below
Run following command to ignore file mod changes

git config core.fileMode false

If you want to run this globally for current logged in user then run following command
in terminal

git config --global core.filemode false

How to recover mysql root password

If you are using linux then you can do this very easily
I have not done this on windows machine
First of all get path of mysqld
run following command

which

And it will output like this
/usr/sbin/mysqld
Remember path can be changed
now stop mysql server using following command

sudo service mysql stop

now start mysql with option –skip-grant-tables, –skip-networking as below

sudo /usr/sbin/mysqld --skip-grant-tables  --skip-networking &

Now open new terminal
and run following commands

sudo mysql
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Reference:
http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html

How to create virtual host using ubuntu/nginx

Create server block file named tutorials.local under path
/etc/nginx/sites-available
and put following contents:

server {
        listen 127.0.0.10:80;
        root /var/www/html/tutorials;
        server_name tutorials.local;
        index index.html index.htm index.php;
        charset utf-8;
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt { access_log off; log_not_found off; }

   access_log off;

   sendfile off;

  client_max_body_size 100m;

 location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_pass  127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REQUEST_SCHEME $scheme;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

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

now run following command in terminal

sudo ln -s /etc/nginx/sites-available/tutorials.local /etc/nginx/sites-enabled/

Now restart nginx

sudo service nginx restart
Create hosts entry
sudo vi /etc/hosts

and add following at the end of file

127.0.0.10 tutorials.local

How to upload file from local to remote machine or vise versa

How to upload file from local to remote machine??

By using following command we can upload file from local machine to remote machine using terminal.

scp filename.zip username@remote.machine:/destination-derectory

This will use port 22 by default. But if you have to specify custom port then you can use following command.

scp -P 2000 filename.zip username@remote.machine:/destination-derectory

 
By using following command we can download file from remote machine to local machine using terminal.

scp -P 22 user@remoteMachineAddressORIP:/fileDestinatio LocalMachineFolderPAth

How to run secondary skype from terminal safely

When i was working on linux(ubuntu), i started secondary skype from terminal using follwing command:

skype --secondary

after executing this command skype started but i was unable to do any work using terminal
then i have done some research and found a command Continue reading How to run secondary skype from terminal safely

How to create virtual host on ubuntu apache2

create conf file under /etc/apache2/sites-available/
name it as vhosts.conf and put following contents

<VirtualHost 127.0.0.3:80>
	ServerAdmin webmaster@test.dev
	ServerName test.dev
	ServerAlias www.test.dev
	DocumentRoot /var/www/html/projects/test
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> 

run following command to enable site

sudo a2ensite vhosts.conf

run following command to restart apache service

sudo service apache2 restart

run following command to enable rewrite mode

sudo a2enmod rewrite 

and thats it, now you can access test.dev in your browser.