VPS Setup Part 7 – Create the Virtual Host Website

Today is going to be another heavy day.

Step Seven – Create the Website

Create Directory Structure

mkdir -p /home/<username>/public_html/<domain.name>/{public,private,log,backup}

where <username> is your username in the VPS and <domain.name> is the name of the domain that you are creating.

Create Default Index Page

In /home/<username>/public_html/<domain.name>/public/, create an index.php file as a placeholder.  I generally create the standard phpinfo page:

<?php
phpinfo();
?>

Create the vhost File

Open /etc/nginx/sites-available/<domain.name> in a text editor as root:

sudo nano /etc/nginx/sites-available/<domain.name>

where <domain.name> is the website that you are creating.

Add the following as the content, replacing <domain.name> and <username> accordingly:

server {

listen   80;
server_name <domain.name>;
#rewrite ^/(.*) http://www.<domain.name> permanent;

access_log /home/<username>/public_html/<domain.name>/log/access.log;
error_log /home/<username>/public_html/<domain.name>/log/error.log;

location / {

root   /home/<username>/public_html/<domain.name>/public/;
index  index.php;
# wordpress fancy rewrites
if (-f $request_filename) {
break;
}
if (-d $request_filename) {
break;
}
rewrite ^(.+)$ /index.php?q=$1 last;

}

location ~ .*\.php[345]?$ {
include /etc/nginx/fcgi.conf;
fastcgi_pass    127.0.0.1:10005;
fastcgi_index   index.php;
fastcgi_param SCRIPT_FILENAME /home/<username>/public_html/<domain.name>/public$fastcgi_script_name;
}

}

server {

listen   80;
server_name www.<domain.name>;

access_log /home/<username>/public_html/<domain.name>/log/access.log;
error_log /home/<username>/public_html/<domain.name>/log/error.log;

location / {

root   /home/<username>/public_html/<domain.name>/public/;
index  index.php;
# wordpress fancy rewrites
if (-f $request_filename) {
break;
}
if (-d $request_filename) {
break;
}
rewrite ^(.+)$ /index.php?q=$1 last;

}

location ~ .*\.php[345]?$ {
include    /etc/nginx/fcgi.conf;
fastcgi_pass    127.0.0.1:10005;
fastcgi_index    index.php;
fastcgi_param SCRIPT_FILENAME /home/<username>/public_html/<domain.name>/public$fastcgi_script_name;
}

}

Enable the Website

sudo ln -s /etc/nginx/sites-available/<domain.name> /etc/nginx/sites-enabled/<domain.name>

Restart nginx

sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start

Part 8

Tomrrow is the final installment on this series. We are finally going to get WordPress up and running.

GD Star Rating
loading...
GD Star Rating
loading...

Related Articles

Random Articles

Post a Comment