.

Maintain Unmanaged VPS – Part 1: Add Web Sites Nginx Cheatsheet

English   English (change)

Maintain Unmanaged VPS – Part 1: Add Web Sites Nginx Cheatsheet

website file structure image

Create additional sites & blogs quickly & easily. After creating the DNS entries, just add a vhost file, its symlink, restart Nginx and go play.

OK. So I did this guide already, already! But as this is one of the main things people do with a VPS – adding extra domains – I figured it wouldn’t hurt to provide a shortcut cheatsheet too, minus the blarney.

This tutorial presumes you have already set up a site or blog with the VPS Bible, and therefore have already enabled FastCGI and, for WordPress, the required FURL & caching scripts. If not, check out the VPS Bible index. Otherwise, just substitute “mydomain.com” for your_domain.tld throughout this how-to.

If you do want the detail, the why’s, the where’s, the wherefore’s, then you can check out the detailed tutorial here.

[sniplet guvSellBox]
[sniplet vpsIndexSell]

Create DNS Records

Add the DNS settings as explained here.

Add Site Directory Structure

At the terminal, type:-

[text]sudo mkdir -p /home/public_html/mydomain.com/{public,private,log,backup}[/text]

Create a Temporary Homepage (optional)

You don’t have to bother with this, but I guess some folks will find it handy.

Type:-

[text]sudo nano /home/public_html/mydomain.com/public/index.html[/text]

.. hit return and paste:-

[text]

It works!

[/text]

Add Virtual Host (vhost) with FastCGI, FURL Support & Optional WordPress Caching

Type this:-

[text]sudo nano /usr/local/nginx/sites-available/mydomain.com[/text]

Return and paste this:-

[text]
server {
listen 80;
server_name www.mydomain.com;
rewrite ^/(.*) http://mydomain.com/$1 permanent;
}

server {

listen 80;
server_name mydomain.com;

access_log /home/public_html/mydomain.com/log/access.log;
error_log /home/public_html/mydomain.com/log/error.log;

location /
{

root /home/public_html/mydomain.com/public/;
index index.php index.html;

# Basic version of WordPress parameters, supporting nice permalinks.
# include /usr/local/nginx/conf/wordpress_params.regular;
# Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
include /usr/local/nginx/conf/wordpress_params.super_cache;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/public_html/mydomain.com/public/$fastcgi_script_name;
}
}
[/text]

Option: If you don’t use WordPress with this site, delete the following lines from the above:-

[text]
# Basic version of WordPress parameters, supporting nice permalinks.
# include /usr/local/nginx/conf/wordpress_params.regular;
# Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
include /usr/local/nginx/conf/wordpress_params.super_cache;
[/text]

Option: If you do want WordPress, and want both pretty permalinks and WP Super Caching support, leave the above, as is.

Option: If you do want WordPress, and want pretty permalinks but not WP Super Caching, swap this:-

[text]
# Basic version of WordPress parameters, supporting nice permalinks.
# include /usr/local/nginx/conf/wordpress_params.regular;
# Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
include /usr/local/nginx/conf/wordpress_params.super_cache;
[/text]

.. for this :-

[text]
# Basic version of WordPress parameters, supporting nice permalinks.
include /usr/local/nginx/conf/wordpress_params.regular;
# Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
# include /usr/local/nginx/conf/wordpress_params.super_cache;
[/text]

Save the file.

Create the Symlink and Restart Nginx

Paste this into the terminal:-

[text]sudo ln -s /usr/local/nginx/sites-available/mydomain.com /usr/local/nginx/sites-enabled/mydomain.com[/text]

And reboot the web server by typing ..

[text]sudo /etc/init.d/nginx stop && sleep 2 && sudo /etc/init.d/nginx start[/text]

.. Or if you followed Set Up Unmanaged VPS (4 Newbies) – Part 7: Edit bashrc for User-Friendly Linux, plus System Updates, just type:-

[text]n2r[/text]

Upload your new domain’s site files and go check it. If you’re relocating an existing site, you should read this for a seamless move.

[sniplet vpsIndex]

.