Tag Archives: restart service

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