Archive

Install VNC Server On Ubuntu

The following simple guide help you to setup the VNC server on Ubuntu machines, VNC helps to share the desktop with the other machines which has a client installed. VNC server and client are not installed by default, you need to setup the vnc server manually. In windows, VNC shares the console desktop with other machine; but in Linux, it shares the vnc desktop sessions instead of console desktop.

Install vncserver.

sudo apt-get install vnc4server

You need to setup the password to access the desktop, So enter the following command to setup password of your wish.

vncpasswd

Start VNC server.

vncserver

You will get a information about the desktop session. Desktop session is 1 as per below information, if you need another session issue the vncserver command on terminal; you will get a session 2 and increments every time when issuing the same command again.

 

Assuming that you have created only one desktop session. Default listening port is 5900, If you have created first session it will be 5901 and so on.

Take remote desktop.
ipaddress:5901 or ipaddress:1
You will be asked to enter the password, after entering the password; you will get the vnc desktop session instead of console desktop. To get a console desktop, you will need to setup remote desktop sharing on Ubuntu 13.04. That’s all you have successfully configured VNC server on Ubuntu 13.04

How To Install Squid Proxy on CentOS 6

Step 1 – Spin up a CentOS 6.3 x64 droplet


Step 2 – Install Squid


yum -y install squid
chkconfig squid on

Step 3 – Setup Access Restrictions


Since this Squid proxy would allow anyone using it to make connections from your droplet’s IP address, you would want to restrict access to it.

You can register a free dynamic IP from services like noip.com

If you would like to use this Squid proxy from your phone, you would have to install a dynamic DNS update client.

You can use applications like Dynamic DNS Client for Android, or FreeDynPro for iOS.

Once you have a dynamic IP hostname, you can update it from your router at home, mobile device, or an API call.

This hostname should be added to /etc/squid/squid.conf. Edit the file and add your hostname (nyproxy1.no-ip.org in our case):

acl localnet src nyproxy1.no-ip.org

Setup a crontab that reloads Squid every hour, in case your IP address changes:

echo 0 */1 * * * service squid reload >> /var/spool/cron/root

Step 4 – Configure Squid Proxy


By default, Squid listens on port 3128. If you would like to use a different port, modify/etc/squid/squid.conf

http_port 3128

If you would like to browse through this Squid proxy and not have it detected as a proxy, setup anonymous settings by adding these lines to /etc/squid/squid.conf:

via off
forwarded_for off

request_header_access Allow allow all 
request_header_access Authorization allow all 
request_header_access WWW-Authenticate allow all 
request_header_access Proxy-Authorization allow all 
request_header_access Proxy-Authenticate allow all 
request_header_access Cache-Control allow all 
request_header_access Content-Encoding allow all 
request_header_access Content-Length allow all 
request_header_access Content-Type allow all 
request_header_access Date allow all 
request_header_access Expires allow all 
request_header_access Host allow all 
request_header_access If-Modified-Since allow all 
request_header_access Last-Modified allow all 
request_header_access Location allow all 
request_header_access Pragma allow all 
request_header_access Accept allow all 
request_header_access Accept-Charset allow all 
request_header_access Accept-Encoding allow all 
request_header_access Accept-Language allow all 
request_header_access Content-Language allow all 
request_header_access Mime-Version allow all 
request_header_access Retry-After allow all 
request_header_access Title allow all 
request_header_access Connection allow all 
request_header_access Proxy-Connection allow all 
request_header_access User-Agent allow all 
request_header_access Cookie allow all 
request_header_access All deny all

Step 5 – Start Squid proxy service


service squid start

Step 6 – Modify your browser’s proxy settings


Add your droplet’s IP address and port to your browser’s proxy settings.

Step 7 – Verify Squid proxy works


Navigate over to whatismyip.com

And you are all done!

Using More Than Two IPs (bind) In Lighttpd For Virtual Hosting

Virtual hosting is nothing but the provision of Web server hosting services so that a company (or individual) doesn’t have to purchase and maintain its own Web server and connections to the Internet.

Lighttpd does support or allows you to bind more than two IP address simultaneously using $SERVER[“socket”]..

For example,
IP # 1: 192.168.1.1 domain domain.com
IP # 2: 192.168.1.2 domain domain2.com

Open lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf

First use server.bind and server.port to setup 192.168.1.1 IP
server.port = 80
server.bind = "192.168.1.1"

Now define domain.com virtual host:
$HTTP["host"] == "www.domain.com" {
server.document-root = "/home/lighttpd/domain.com/http"
server.errorlog = "/var/log/lighttpd/domain.com/error.log"
accesslog.filename = "/var/log/lighttpd/domain.com/access.log"
}

Next use $SERVER[“socket”] to bind 192.168.1.2:80 for domain2.com domain:
$SERVER["socket"] == "192.168.1.2:80" {
server.document-root = "/home/lighttpd/domain2.com/http"
server.errorlog = "/var/log/lighttpd/domain2.com/error.log"
accesslog.filename = "/var/log/lighttpd/domain2.com/access.log"
}

Save and close config file. Restart the lighttpd:
# /etc/init.d/lighttpd restart

How To Install VNC Server On CentOS

VNC (Virtual Network Computing ) is a graphical desktop sharing system that uses the Remote Frame Buffer protocol to remotely control another coumputer on a network.

To run the VNC Server on CentOS, we have to install these required packages:

Code: [Select]
yum groupinstall Desktop
yum install tigervnc-server
yum install xorg-x11-fonts-Type1
yum install vnc

To start VNC Server on boot

Code: [Select]
chkconfig vncserver on

To setup users’ VNC password:

Code: [Select]
vncpasswd

Edit the /etc/sysconfig/vncservers file:

Code: [Select]
nano /etc/sysconfig/vncservers

Add the following to the end of the file:

Code: [Select]
VNCSERVERS="1:arbab"
VNCSERVERARGS[1]="-geometry 1024x600"

The iptables rules need to be amended to open the VNC ports:

Code: [Select]
iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT
service iptables save
service iptables restart

Restart the VNC Server:

Code: [Select]
service vncserver restart

Now kill the VNC Server:

Code: [Select]
vncserver -kill :1

Edit the xstartup file in .vnc directory:

Code: [Select]
nano .vnc/xstartup

Comment the last line and run the Gnome:

Code: [Select]
#twm & 
exec gnome-session &

Restart the service:

Code: [Select]
service vncserver restart

Now, download VNCViewer onto our desktop computer from which we want to access the shared desktop.
Connect using ServerIP/Name:1 (:1 is for the VNC server window)

http://www.realvnc.com/download/viewer/

Enter the password that we created using the vncpasswd command:

Ability to connect for multiple users:

Create a local user, using the following command:

Code: [Select]
adduser ali

Create a password for newly created user:

Code: [Select]
passwd ali

Switch to the newly created user and run vncpasswd command for it:

su ali

Code: [Select]
vncpasswd

Edit the /etc/sysconfig/vncservers file:

Code: [Select]
nano /etc/sysconfig/vncservers

Add these lines for new user:

Code: [Select]
VNCSERVERS="1:arbab 2:ali"
VNCSERVERARGS[1]="-geometry 1024x600"
VNCSERVERARGS[2]="-geometry 1024x600"

Restart the VNC service:

Code: [Select]
service vncserver restart

Kill the vncserver session for new user and edit the xstartup file:

Code: [Select]
su ali
vncserver -kill :2
cd ~
nano .vnc/xstartup

Modify the file so it looks like this:

Code: [Select]
#twm & 
exec gnome-session &

Restart the VNC service:

Code: [Select]
service vncserver restart

Connect with newly created user using centos:2, Where centos is my server name:

Enter the password that we created using the vncpasswd command:

Install GeoIP Module For Country/City Level Geo Targeting (NGINX)

Install MaxMind C API

Type the following commands to install MaxMind C API:
# cd /tmp
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
# tar -zxvf GeoIP.tar.gz
# cd GeoIP-1.4.6
yum install zlib-devel
# ./configure
# make
# make install

You need to configure dynamic linker run time bindings as follows:
# echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf
Run ldconfig to activate configuration:
# ldconfig
# ldconfig -v | less

Compile nginx With GeoIP Module

Get the latest source code:
# cd /tmp
wget http://nginx.org/download/nginx-0.8.52.tar.gz
# tar -zxvf nginx-0.8.52.tar.gz
# cd nginx-0.8.52
yum install gcc pcre-devel.x86_64 openssl-devel.x86_64
# ./configure --without-http_empty_gif_module --with-poll_module --with-http_stub_status_module --with-http_ssl_module --with-ipv6 --with-http_geoip_module
# make
# make install

Make sure you ./configure nginx with –with-http_geoip_module option.

Grab MaxMind Databases

Type the following command to get the free database of geo_city:
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -O /usr/local/share/GeoIP/GeoLiteCity.dat.gz
gunzip /usr/local/share/GeoIP/GeoLiteCity.dat.gz

Get the free database of geo_country:
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -O /usr/local/share/GeoIP/GeoIP.dat.gz
gunzip /usr/local/share/GeoIP/GeoIP.dat.gz

A Note About MaxMind Paid Version

If you need 99.8% accuracy about IP address use the paid version. Edit /usr/local/etc/GeoIP.conf, enter:
# vi /usr/local/etc/GeoIP.conf
Update config as follows:

 
# see https://www.maxmind.com/app/license_key_login
# Enter your license key here
LicenseKey YOUR_LICENSE_KEY_HERE

# Enter your User ID here
UserId YOUR_USER_ID_HERE

# Enter your Product ID here i.e. 106 geoip country
ProductIds 106

Save and close the file. Get latest licensed version database, enter:
# /usr/local/bin/geoipupdate

nginx Configuration

Edit nginx.conf, enter:
# vi /usr/local/nginx/conf/nginx.conf
Locate http section and update it as follows for geoip country lookup:

 
  ### SET the path to the .dat file used for determining the visitor's country from the IP-address ###
  geoip_country /usr/local/share/GeoIP/GeoIP.dat;

  ### SET FASTCGI Variables ###
  fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
  fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
  fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;

Save and close the file. If you want city level geo targeting set it as follows:

 
  ### SET the path to the .dat file used for determining the visitor's country from the IP-address ###
  geoip_city  /usr/local/share/GeoIP/GeoLiteCity.dat;

  ### SET FASTCGI Variables ###
  fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
  fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
  fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
  fastcgi_param GEOIP_REGION $geoip_region;
  fastcgi_param GEOIP_CITY $geoip_city;
  fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
  fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
  fastcgi_param GEOIP_LATITUDE $geoip_latitude;
  fastcgi_param GEOIP_LONGITUDE $geoip_longitude;

Save and close the file. Finally, reload nginx:
# /usr/local/nginx/sbin/nginx -s reload

PHP Test Script

Create a php test script as follows geoip.php

<html>
<head>
  <title>What is my IP address - determine or retrieve my IP address</title>
 </head>
<body>
 <?php
     if (getenv(HTTP_X_FORWARDED_FOR)) {
        $pipaddress = getenv(HTTP_X_FORWARDED_FOR);
        $ipaddress = getenv(REMOTE_ADDR);
        echo "Your Proxy IP address is : ".$pipaddress. " (via $ipaddress) " ;
    } else {
        $ipaddress = getenv(REMOTE_ADDR);
        echo "Your IP address is : $ipaddress";
    }
    $country = getenv(GEOIP_COUNTRY_NAME);
    $country_code = getenv(GEOIP_COUNTRY_CODE);
    echo "<br/>Your country : $country ( $country_code ) ";
?>
</body>
</html>

Sample outputs:

Fig.01: What is my ip address?

Fig.01: What is my ip address?
You can see working example here.

 

How Do I Find Out MaxMind Database Info?

Type the following command:
# /usr/local/bin/geoiplookup -v 1.2.3.4
Sample outputs:

GeoIP Country Edition: GEO-106 20101001 Build 1 Copyright (c) 2010 MaxMind Inc All Rights Reserved

How Do I Use Country Code in nginx Configuration?

You can use it as follows:

 
### USA specific config ###
 if ($geoip_country_code = US) {
    do something here for USA visitors;
    # e.g. set root path /var/www/html/content/usa/;
 }

### India specific config ###
 if ($geoip_country_code = IN) {
    do something here for Indian visitors ;
    # e.g. set root path /var/www/html/content/india/;
 }

How Do I Test City Level Geo Targeting?

Use the following php code:

<html>
<head>
 <title>What is my IP address - determine or retrieve my IP address</title>
</head>
<body>
<?php
    if (getenv(HTTP_X_FORWARDED_FOR)) {
        $pipaddress = getenv(HTTP_X_FORWARDED_FOR);
        $ipaddress = getenv(REMOTE_ADDR);
        echo "<br>Your Proxy IP address is : ".$pipaddress. " (via $ipaddress) " ;
    } else {
        $ipaddress = getenv(REMOTE_ADDR);
        echo "<br>Your IP address is : $ipaddress";
    }
  $geoip_city_country_code = getenv(GEOIP_CITY_COUNTRY_CODE);
  $geoip_city_country_code3 = getenv(GEOIP_CITY_COUNTRY_CODE3);
  $geoip_city_country_name = getenv(GEOIP_CITY_COUNTRY_NAME);
  $geoip_region = getenv(GEOIP_REGION);
  $geoip_city = getenv(GEOIP_CITY);
  $geoip_postal_code = getenv(GEOIP_POSTAL_CODE);
  $geoip_city_continent_code = getenv(GEOIP_CITY_CONTINENT_CODE);
  $geoip_latitude = getenv(GEOIP_LATITUDE);
  $geoip_longitude = getenv(GEOIP_LONGITUDE);
  echo "<br>Country : $geoip_city_country_name ( $geoip_city_country_code3 , $geoip_city_country_code ) ";
  echo "<br>Region :  $geoip_region";
  echo "<br>City :  $geoip_city ";
  echo "<br>Postal code :  $geoip_postal_code";
  echo "<br>City continent code :  $geoip_city_continent_code";
  echo "<br>Geoip latitude :  $geoip_latitude ";
  echo "<br>Geoip longitude :   $geoip_longitude ";

?>
</body>
</html>

Sample outputs:

Fig.02: GeoCity Database PHP Script Output

Install, Configure & Optimise PHP5 with PHP5-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
Source : PHP-FPM Website

PHP-FPM is far better than the standard mod_php implementation of PHP and also easier to implement that spawn-fcgi. PHP-FPM works like an application that loads and kills PHP instances as needed. Of all the benefits that it offers, reduced memory usage is the most attractive one.

Step 1 : Add the Dotdeb repository

You can skip this step if you have already added the Dotdeb repository while installing NGINX on your Debian Server. The version of PHP and PHP-FPM in the Dotdeb repository is up-to-date and stable. We need to grab the latest version of PHP to benefit from all new updates and bug fixes.

Step 2 : Installing PHP and PHP-FPM

The following command will do it all for you. I have included some popular PHP modules. You can choose and install the modules that you require.

1
sudo apt-get install php5-cgi php5-cli php5-common php5-curl php5-dev php5-fpm php5-gd php5-idn php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-suhosin php5-tidy php5-xcache php5-xmlrpc php5-xsl php-pear php-soap

This command will install PHP-FPM and auto start the service. PHP-FPM will get added to the startup.

Step 3 : Configuring and Optimising PHP

As you will be using PHP-FPM to process PHP scripts, edit the php.ini file that can be found at /etc/php5/fpm/php.ini. There are a lot of PHP settings that you can configure to optimise PHP for performance, speed and security. The following three are a good starting point.

1
2
3
memory_limit = 64M
expose_php = Off
display_errors = Off

Step 4 : Configuring and Optimising PHP-FPM

Remember, we are setting up a low-end (256MB) web server on Shine Servers. We need to conserve as much memory as possible. Edit the file /etc/php5/fpm/pool.d/www.conf

1
2
3
4
5
6
pm = dynamic
pm.max_children = 10
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 4
pm.max_requests = 500

This will bring down the number of children processes and free up some RAM.

Step 5 : Restart PHP-FPM

1
service php5-fpm restart

This command will restart PHP-FPM.